简体   繁体   English

iOS-单元格图片模糊

[英]iOS - Cell image blurred

I have placed an image in a UITableViewCell and for some reason, the image is a bit blurred... 我将图像放置在UITableViewCell中,由于某种原因,图像有点模糊...

This is what I'm using: 这就是我正在使用的:

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

cell.imageView.image = thumbnail;

Is there another way to provide the desired result but maintain the images quality? 有没有其他方法可以提供所需的结果,但又可以保持图像质量?

Reason : 原因:

The default imageView size is 40x40 and so your image needs to be 80x80 pixels (retina display). 默认的imageView大小为40x40,因此您的图像需要为80x80像素(视网膜显示)。

But the image that you are getting from the "pbs.twimg.com/profile_images/192098593/Apple_normal.png" is 48x48. 但是,您从“ pbs.twimg.com/profile_images/192098593/Apple_normal.png”获得的图像为48x48。

And so it is blurred. 因此它是模糊的。

Solution : 解决方案:

One option is that you add a custom imageView which is 24x24. 一种选择是添加一个24x24的自定义imageView。 (width : 24 & height : 24) Then your image will not show blurred. (宽度:24,高度:24),则图像不会显示模糊。

Or, you can try modifying the height and width of the imageView by subclassing the class UITableViewCell and using its layoutSubviews method. 或者,您可以尝试通过子类化UITableViewCell并使用其layoutSubviews方法来修改imageView的高度和宽度。 The "trick" is to write layout code in this method, otherwise the code does not have any effect : “技巧”是使用此方法编写布局代码,否则该代码没有任何效果:

- (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