简体   繁体   English

图片不适合UIImageView

[英]Image does not fit in UIImageView

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 我有一些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];

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应该可以解决问题,但是您需要确保能够在屏幕上看到整个图像视图,并提供一定的内容大小会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM