简体   繁体   中英

iOS - Cell image blurred

I have placed an image in a UITableViewCell and for some reason, the image is a bit blurred...

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).

But the image that you are getting from the "pbs.twimg.com/profile_images/192098593/Apple_normal.png" is 48x48.

And so it is blurred.

Solution :

One option is that you add a custom imageView which is 24x24. (width : 24 & height : 24) Then your image will not show blurred.

Or, you can try modifying the height and width of the imageView by subclassing the class UITableViewCell and using its layoutSubviews method. 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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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