简体   繁体   English

从XIB加载UIView大小不正确

[英]Load UIView from XIB incorrect size

I'm new to iOS 8, I tried to load a UIView from XIB file with auto layout and size classes option are enabled. 我是iOS 8的新手,我尝试从XIB文件加载具有自动布局和尺寸类别选项的UIView。 I use Inferred size XIB with default size is 600 x 600. But on the simulator the size of view is not fit screen size, it still be 600 x 600 and doesn't fit the screen size like this, it's much bigger than the screen on width: 我使用推断尺寸XIB,默认尺寸为600 x600。但是在模拟器上,视图的尺寸不适合屏幕尺寸,它仍然是600 x 600,并且不适合这样的屏幕尺寸,它比屏幕大得多在宽度上: 在此处输入图片说明

But when I use View Controller widget, it has Resize of NIB option, and it work fine to fit the screen size. 但是,当我使用“视图控制器”小部件时,它具有“调整NIB大小”选项,并且可以很好地适合屏幕尺寸。 Can anybody suggest what should I do to resize UIView to fit screen size? 有人可以建议我如何调整UIView的大小以适合屏幕尺寸吗? Thank you very much, guys! 非常感谢你们!

Update: Here is how I call it: 更新:这是我的称呼: 在此处输入图片说明

And constraint I use: 我使用的约束: 在此处输入图片说明

You should use autolayout and set constraint. 您应该使用自动布局并设置约束。 It is better choice if you need to support multiple device. 如果需要支持多个设备,则是更好的选择。

Try to figure out with these 3 images first. 首先尝试找出这3张图片。 Then I am discussing one by one. 然后,我将一一讨论。

http://imgur.com/mE2dNm8 http://imgur.com/mE2dNm8

http://imgur.com/PVW6yrk http://imgur.com/PVW6yrk

http://imgur.com/LLZkMgx http://imgur.com/LLZkMgx

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

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