I have some base64 data and am trying to put it in my image, which I can do but I can't get it so that it shrinks to just fill the imageView and not make it bigger, here is what I am doing
NSString *base64 =[[NSString stringWithFormat:@"data:image/png;base64,%@", dataString] stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSURL *url = [NSURL URLWithString:base64];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
rdCell.imageView.clipsToBounds = YES;
rdCell.imageView.contentMode = UIViewContentModeScaleAspectFill;
[rdCell.imageView setImage:image];
I have also tried this
NSURL *url = [NSURL URLWithString:base64];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
rdCell.imageView.contentMode = UIViewContentModeScaleAspectFit;
[rdCell.imageView setImage:image];
But then I see the image larger than the original size of the image view, why won't it stay inside?
Thanks
您必须改为使用contentMode UIViewContentModeScaleAspectFit
!
UIViewContentModeScaleToFill
应该可以解决问题,但是您需要确保能够在屏幕上看到整个图像视图,并提供一定的内容大小会有所帮助。
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.