简体   繁体   English

UIImageView不能延伸到整个屏幕

[英]UIImageView does not stretch to whole screen

I prototype an app and navigation and my UIImageView in ViewControllers, which I created in Storyboard (Xcode 6) does not stretch to full screen. 我对应用程序和导航进行了原型设计,并且在StoryController(Xcode 6)中创建的ViewControllers中的UIImageView并没有全屏显示。 For example, I have UIImageView with 640×1136 image. 例如,我有640×1136图像的UIImageView。 If I run it on iPhone 5, it shows me full screen. 如果我在iPhone 5上运行它,它将显示全屏。 But if I run it on iPhone 6 or 6 Plus, it locates in top left corner. 但是,如果我在iPhone 6或6 Plus上运行它,则它位于左上角。 I read so many topics and articles, but nothing helped. 我读了很多主题和文章,但没有任何帮助。

在此处输入图片说明

在此处输入图片说明

Make sure your UIImage is in an UIImageView and then either add constraints or change the content mode like this: 确保您的UIImageUIImageView ,然后添加约束或更改内容模式,如下所示:

myImageView.contentMode = UIViewContentModeScaleAspectFit;

Or change it in the story board in the attributes inspector under view . 或在视图中的属性检查器的故事板上更改它。

Here is a list of all the values you can set for this property. 这是您可以为此属性设置的所有值的列表。

Edit : reading your issue over, I think you definitely need to add constraints to your view. 编辑 :仔细阅读您的问题,我认为您绝对需要在视图中添加约束。 There are lots of tutorials on how to do this: here is apples. 有很多关于如何执行此操作的教程: 这是苹果。

You add your constraints by clicking the pin menu, and then clicking on the four red brackets and clicking "Add Constraints". 通过单击图钉菜单,然后单击四个红色括号并单击“添加约束”,可以添加约束。

在此处输入图片说明

只需将AspectRatio约束添加到imageView

使用自动版式并在其上添加所有四个约束(右上,左,下)。

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

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