xcode 无法在 IB 中调整 UIView 的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1087676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't resize UIView in IB
提问by
Probably something simple, but I can't figure why I cannot resize a UIView in a xib in Interface Builder.
可能很简单,但我不明白为什么我无法在 Interface Builder 的 xib 中调整 UIView 的大小。
I created a new view XIB in xcode and in the size inspector, the width and height are disabled and grayed out to 320 by 460. This is strange since I can change the size for the other two views (associated with the other two tab bar items).
我在 xcode 和尺寸检查器中创建了一个新视图 XIB,宽度和高度被禁用并灰显为 320 x 460。这很奇怪,因为我可以更改其他两个视图的大小(与其他两个选项卡栏相关)项目)。
I am not sure if this has anything to do with but I recently updated the sdk to 3.
我不确定这是否与此有关,但我最近将 sdk 更新为 3。
Thanks!
谢谢!
回答by teabot
I think that you cannot edit the size while simulating any user interface elements such as the status bar in Interface Builder. You could try turning the simulated elements off if any are enabled. Not exactly sure why this is, so would appreciate feedback from anyone who knows why exactly this is - there must be a good reason.
我认为您不能在模拟任何用户界面元素(例如 Interface Builder 中的状态栏)时编辑大小。如果启用了任何模拟元素,您可以尝试关闭模拟元素。不完全确定这是为什么,所以希望任何知道这究竟是为什么的人提供反馈 - 必须有一个很好的理由。
回答by Houman
In order to achieve that in XCode 4.6.3/5.0.2 you need to follow the screenshot below:
为了在 XCode 4.6.3/5.0.2 中实现这一点,您需要按照以下屏幕截图进行操作:
- Under 'File Inspector' -> untick
Use Auto Layout
- Click on Attributes Selector & Choose
Freeform
for Size
- 在“文件检查器”下 -> 取消勾选
Use Auto Layout
- 单击属性选择器并选择
Freeform
大小
This is needed when creating a headerView for a tableView
为 tableView 创建 headerView 时需要这样做
回答by Thomas Mon
The part that you are looking for is on the first Inspector panel (Command-1). Right at the top there is a section that is labeled Simulated User Interface Elements. By default the Status Bar is on. You need to make sure all three are set to None.
您要查找的部分位于第一个检查器面板 (Command-1) 上。在顶部有一个部分,标记为模拟用户界面元素。默认情况下,状态栏是打开的。您需要确保所有三个都设置为无。
回答by lol
As at Xcode 4.2, iOS 5.0.1, the default simulated metrics include simulating the 'size' attribute of UIViewControllers to 'Inferred'
在 Xcode 4.2、iOS 5.0.1 中,默认的模拟指标包括将 UIViewControllers 的“size”属性模拟为“Inferred”
If you change this attribute to 'Freeform' then you are able to resize the UIView contained within the UIViewController while also simulating the status bar (or any other of the simulations for that matter)
如果您将此属性更改为“Freeform”,则您可以调整包含在 UIViewController 中的 UIView 的大小,同时还可以模拟状态栏(或任何其他与此相关的模拟)
回答by lol
Just go to the inspector, go to the first panel (or press command-1) and then change the fields marked Status Bar, Top Bar, and Bottom Bar to None under the section called "Simulated User Interface Elements". You may need to click the little triangle to make them visible.
只需转到检查器,转到第一个面板(或按 command-1),然后在名为“模拟用户界面元素”的部分下将标记为状态栏、顶部栏和底部栏的字段更改为无。您可能需要单击小三角形才能使它们可见。
回答by cramhead
Funny I have a similar problem. I've removed all views from the xib file and re-added a view. Set the status bar to being "unspecified" so that the status bar is not accommodated for. The view, when added, get created with x=0, y=0, w=320 h=460 instead of (0,0,320,480) as I would have expected. After changing the height to 480 and connecting it to file's owner and changing the color to make it distinctive in relation to the background. I fount that there was a white band between the top of the screen and the view. I augmented my code with:
有趣的是我也有类似的问题。我已经从 xib 文件中删除了所有视图并重新添加了一个视图。将状态栏设置为“未指定”,以便不容纳状态栏。添加后,视图使用 x=0, y=0, w=320 h=460 而不是 (0,0,320,480) 创建,正如我预期的那样。将高度更改为 480 并将其连接到文件所有者并更改颜色以使其与背景不同。我发现屏幕顶部和视图之间有一条白带。我增加了我的代码:
#define RECTLOG(rect) (NSLog(@"" #rect @" x:%f y:%f w:%f h:%f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height ));
within viewDidLoad
在 viewDidLoad 中
- (void)viewDidLoad { [super viewDidLoad]; RECTLOG(self.view.frame); }
Turns out that the view is as it's loaded from IB is actually (0, 20, 320, 480) As a work around I reset the view's frame with self.view.frame = CGRectMake(0, 0, 320, 480);
事实证明,从 IB 加载的视图实际上是 (0, 20, 320, 480) 作为解决方法,我使用 self.view.frame = CGRectMake(0, 0, 320, 480); 重置了视图的框架;
I'm using IB 3.2.5
我正在使用 IB 3.2.5
I'd love to know of a little fix for this one.
我很想知道这个的一个小修复。
回答by PowerAktar
I've noticed that the UIView automatically created when creating the xib file cannot be resized from the sizing panel or the edge handles.
我注意到创建 xib 文件时自动创建的 UIView 无法从大小调整面板或边缘手柄调整大小。
All I did was to add another UIView and dragged everything from my old UIView to the new one then deleted the old one.
我所做的只是添加另一个 UIView 并将所有内容从旧 UIView 拖到新 UIView 然后删除旧 UIView。
It solved the problem for me but yes, I think there is an underlying issue with the interface builder for Apple to solve (somebody correct me if I'm wrong).
它为我解决了这个问题,但是是的,我认为 Apple 需要解决的界面构建器存在潜在问题(如果我错了,有人会纠正我)。
I'm Using XCode 4 integrated Interface builder.
我正在使用 XCode 4 集成界面构建器。
回答by jeet.chanchawat
I sorted it out in a different way...
我用不同的方式整理了它...
open your xib with your favourite text editor and edit this line
用你最喜欢的文本编辑器打开你的 xib 并编辑这一行
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CompassViewController">
CompassViewController
is your class name you are trying to link your nib/xib with.
CompassViewController
是您试图将您的笔尖/xib 与之链接的班级名称。
Just edit your class name with the correct class name and you are done ;)
只需使用正确的班级名称编辑您的班级名称即可完成;)