In my custom tableViewCell, I have an imageView (and not a default imageViewView tableViewCell) that fills the whole cell. It is configured in IB (and by code) with contentMode UIViewContentModeAspectFill , and it is copied to frames. Whenever I change the imageView image to an image uploaded using [UIImage imageNamed:...] , it resizes and matches the image as desired and expected. However, when a set of images is uploaded using [UIImage imageWithData:...] , the image is set but not changed.
The code that loads the image with the data itself runs in the background thread and looks like this:
- (void)getImage:(NSString *)URL { NSError *error = nil; UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:URL] options:NSDataReadingMapped error:&error]]; if (!error){ [self.thumbView setImage:image]; [self.thumbView setContentMode:UIViewContentModeScaleAspectFill]; } }
I tried to set the image in the main thread, in layoutSubviews , but it always gives the same result - it does not resize to fill the imageView. I added an image (JPG) to the application package and installed it programmatically using [UIImage imageNamed:...] , which works, but the application should get the data from the URL.
I also tried using the UIImageView + AFNetworking class to set the asynchronous image instead of creating my own stream, but this also does not work.
Why is the image related to the UIImageView contentMode not loading from the data? Any help is appreciated. Neither JPEG nor PNG work.
source share