[英]Image does not fit in UIImageView
我有一些base64数据,正在尝试将其放入我的图像中,我可以这样做,但我无法获取,因此它会缩小以仅填充imageView而不是使其变大,这就是我正在做的
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];
我也尝试过
NSURL *url = [NSURL URLWithString:base64];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
rdCell.imageView.contentMode = UIViewContentModeScaleAspectFit;
[rdCell.imageView setImage:image];
但是然后我看到的图像大于图像视图的原始大小,为什么它不留在内部?
谢谢
您必须改为使用contentMode UIViewContentModeScaleAspectFit
!
UIViewContentModeScaleToFill
应该可以解决问题,但是您需要确保能够在屏幕上看到整个图像视图,并提供一定的内容大小会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.