繁体   English   中英

图片无法按比例显示在图片视图中

[英]Image won't fit in scale to fill mode in image view

这是一个非常简单的任务,但是对我来说不起作用。 这是我所做的:

  1. 在情节提要中,将图像视图添加到我的控制器中,将每一侧固定到Superview,且距离为0。
  2. 将图像视图的图像设置为646 x 1140的PNG图像。
  3. 设置模式以缩放以填充

然后在我的模拟器中,视图控制器如下所示:

错误的屏幕截图

如屏幕截图所示,图像周围有空白。

我可以确认图像本身周围没有空格,并且图像视图很好地固定在其视图的四个侧面。 那么为什么会这样呢? 我有想念吗?

可能是您的图像从左到右一点透明,如果白色也会改变,则尝试更改veiw的颜色,然后它将确认。

将您的图像设置为

yourimage.contentMode = UIViewContentModeScaleAspectFit;

根据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,
};

暂无
暂无

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

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