I am setting an table cell ImageView from a URL like the following:
NSURL *url = [[NSURL alloc] initWithString:[account valueForKeyPath:@"Avatar"]];
[cell.imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default.png"]];
I am then using a table cell subclass and resizing the image and making it round like the following:
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.bounds = CGRectMake(0,0,32,32);
self.imageView.layer.cornerRadius = 16;
self.imageView.clipsToBounds = YES;
}
This works great until I actually tap on a table row. It will then shift the image to the left some pixels.
It's only the images that aren't a perfect square. Example 100x75 instead of 100x100
I must be missing something small here? Here is a small image showing the offset:
FYI I'm referencing this post: How do I make UITableViewCell's ImageView a fixed size even when the image is smaller
EDIT
I've also tried this as the table cell cellForRowAtIndexPath
:
This seems to work, however, for some reason when the table view is loaded not all images are loaded in until I start scrolling
[[SDWebImageManager sharedManager] downloadImageWithURL:url options:0 progress: nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
// resize image code here, then set below
cell.imageView.image = image;
}];