It's a really simple task but somehow it just did not work for me. This is what I did:
Then in my simulator, the view controller looks like this:
As the screenshot shows, there are white spaces around the image.
I can confirm the image itself does not have white spaces around it, and the image view pins well to the four sides of its superview. So why does it look like this? Did I miss anything?
可能是您的图像从左到右一点透明,如果白色也会改变,则尝试更改veiw的颜色,然后它将确认。
set your image as
yourimage.contentMode = UIViewContentModeScaleAspectFit;
some other variation using as per apple documentation
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
};
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.