繁体   English   中英

iOS-单元格图片模糊

[英]iOS - Cell image blurred

我将图像放置在UITableViewCell中,由于某种原因,图像有点模糊...

这就是我正在使用的:

NSURL *urlForProfileImage = [NSURL URLWithString: [_currentTweet[@"user"] objectForKey:@"profile_image_url_https"]];
UIImage *thumbnail = [UIImage imageWithData: [NSData dataWithContentsOfURL:urlForProfileImage]];

cell.imageView.image = thumbnail;

有没有其他方法可以提供所需的结果,但又可以保持图像质量?

原因:

默认的imageView大小为40x40,因此您的图像需要为80x80像素(视网膜显示)。

但是,您从“ pbs.twimg.com/profile_images/192098593/Apple_normal.png”获得的图像为48x48。

因此它是模糊的。

解决方案:

一种选择是添加一个24x24的自定义imageView。 (宽度:24,高度:24),则图像不会显示模糊。

或者,您可以尝试通过子类化UITableViewCell并使用其layoutSubviews方法来修改imageView的高度和宽度。 “技巧”是使用此方法编写布局代码,否则该代码没有任何效果:

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imageView.bounds = CGRectMake(0,0,24,24);
    self.imageView.frame = CGRectMake(0,0,24,24);
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;

    CGRect tmpFrame = self.textLabel.frame;
    tmpFrame.origin.x = 30;
    self.textLabel.frame = tmpFrame;

    tmpFrame = self.detailTextLabel.frame;
    tmpFrame.origin.x = 30;
    self.detailTextLabel.frame = tmpFrame;

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM