gpt4 book ai didi

ios - 下载的图片比想要的大

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:38 25 4
gpt4 key购买 nike

问题

我正在开发一个应用程序,我可以从上传到网站的 JSON 文件下载数据。下载的所有内容都正确显示...但是我有这个大小为 54x54 的 UIImageView,每当我尝试从 JSON 文件下载图像时,它都会显示其原始大小而不是 ImageView 的大小。

对于 Retina 设备来说这是一个问题,因为图像必须与 ImageView 大小相同。

我怎样才能使图像以正确的尺寸调整大小?

http://i.stack.imgur.com/qOQz5.png

这是我拥有的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

UILabel *label;

label = (UILabel *)[cell viewWithTag:1];
label.text = [arrayTitle objectAtIndex:indexPath.row];
label.frame = CGRectMake(70, 8, 209, 21);

label = (UILabel *)[cell viewWithTag:2];
label.text = [arraySubtitle objectAtIndex:indexPath.row];
label.frame = CGRectMake(70, 29, 209, 33);
label.numberOfLines = 2;

UIImageView *imgView = (UIImageView *)[cell viewWithTag:0];
imgView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [arrayImage objectAtIndex:indexPath.row]]]]];
imgView.frame = CGRectMake(8, 8, 54, 54);

cell.imageView.image = imgView.image;

return cell;
}

最佳答案

解决方案

我创建了一个 UITableViewCell 类并实现了我的标签和 ImageView 的所有属性:

- (void)awakeFromNib {

imageView.frame = CGRectMake(8, 8, 54, 54);
title.frame = CGRectMake(79, 14, 200, 21);
subtitle.frame = CGRectMake(79, 31, 200, 33);
date.frame = CGRectMake((self.window.frame.size.width - 140), 0, 100, 21);
}

然后我在我的 TableViewController 中调用它:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
HomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

cell.title.text = [arrayTitle objectAtIndex:indexPath.row];
cell.subtitle.text = [arraySubtitle objectAtIndex:indexPath.row];
cell.date.text = [arrayDate objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [arrayImage objectAtIndex:indexPath.row]]]]];

return cell;
}

关于ios - 下载的图片比想要的大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27683473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com