I’m downloading thumbnail images from youtube JSON web service using SDWebImage, in order to set them in a table view cell. The problem is that the download image is 120×90, too big for my needs , as I want to fit it in a UIImageView of 75×75. While the images are cached in the placeholder, they look correct, but once cache is finished, they look in the 120×90 ratio size. I tried setContentMode:UIViewContentModeScaleToFill, but it doesn’t work, so I don’t know how to solve this issue.
NSString *path= [thumbnail valueForKey:@"sqDefault"];
[cell.imageView setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[cell.imageView setContentMode:UIViewContentModeScaleToFill];
CALayer * l = [cell.imageView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:5.0];
Many thanks
EDITED:
I have set content mode in the custom cell extended class:
newsCell.m
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self.Image setContentMode:UIViewContentModeScaleToFill];
}
return self;
}
And here is the cell creation code:
multimedia.m
newsCell *cell = [self.tableView
dequeueReusableCellWithIdentifier:@"news"];
if (cell == nil) {
cell = [[newsCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"news"];
}
The issue is that if (cell == nil) is never called because first statement is creating cell, so initWithStyle is not called and content mode is not set, but if I delete first statement, cell is not created. I don’t know how to manage it.
Thanks
Try these two options and see which better fits your needs:
If these don’t work, I am guessing it is because the UITableViewCell is setting the contentMode on the UIImageView — in this case you should create a subclass of UITableViewCell that contains a UIImageView with the proper contentMode set. Then you can use your custom UITableViewCell subclass in your UITableView.