不能在IB中调整UIView的大小

时间:2023-01-22 18:00:32

Probably something simple, but I can't figure why I cannot resize a UIView in a xib in 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,在size检查器中,宽度和高度被禁用,灰色显示为320×460。这很奇怪,因为我可以更改其他两个视图的大小(与其他两个选项卡项相关联)。

I am not sure if this has anything to do with but I recently updated the sdk to 3.

我不确定这是否与此有关,但我最近将sdk更新为3。

Thanks!

谢谢!

8 个解决方案

#1


79  

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.

我认为您不能在模拟任何用户界面元素(如接口构建器中的状态栏)时编辑大小。如果启用了模拟元素,您可以尝试关闭它们。不知道为什么会这样,所以如果有人知道为什么会这样,我们会感激他的反馈——一定有一个很好的理由。

#2


65  

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中实现这一点,您需要遵循下面的截图:

  1. Under 'File Inspector' -> untick Use Auto Layout
  2. 在“文件检查器”-> untick使用自动布局。
  3. Click on Attributes Selector & Choose Freeform for Size
  4. 单击“属性选择器”并为大小选择“*格式”

This is needed when creating a headerView for a tableView

在为tableView创建headerView时,需要这样做。

不能在IB中调整UIView的大小

#3


40  

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.

您正在寻找的部分在第一个检查面板上(命令1)。在最上面有一个部分标记为模拟用户界面元素。默认情况下,状态栏是打开的。您需要确保这三个都设置为None。

#4


26  

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”属性以“推断”

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的大小同时也可以模拟状态栏(或其他类似的模拟)

#5


4  

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),然后在名为“模拟用户界面元素”的区域中更改标记状态栏、顶部栏和底部条的字段。你可能需要点击这个小三角形使它们可见。

#6


1  

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拖到新的然后删除旧的。

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).

它为我解决了问题,但是是的,我认为苹果的接口构建器有一个潜在的问题需要解决(如果我错了,请指正)。

I'm Using XCode 4 integrated Interface builder.

我使用XCode 4集成接口构建器。

#7


0  

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,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.

我很想知道这个问题的解决办法。

#8


0  

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是您试图链接nib/xib的类名。

Just edit your class name with the correct class name and you are done ;)

只要用正确的类名编辑类名,就完成了;)

#1


79  

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.

我认为您不能在模拟任何用户界面元素(如接口构建器中的状态栏)时编辑大小。如果启用了模拟元素,您可以尝试关闭它们。不知道为什么会这样,所以如果有人知道为什么会这样,我们会感激他的反馈——一定有一个很好的理由。

#2


65  

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中实现这一点,您需要遵循下面的截图:

  1. Under 'File Inspector' -> untick Use Auto Layout
  2. 在“文件检查器”-> untick使用自动布局。
  3. Click on Attributes Selector & Choose Freeform for Size
  4. 单击“属性选择器”并为大小选择“*格式”

This is needed when creating a headerView for a tableView

在为tableView创建headerView时,需要这样做。

不能在IB中调整UIView的大小

#3


40  

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.

您正在寻找的部分在第一个检查面板上(命令1)。在最上面有一个部分标记为模拟用户界面元素。默认情况下,状态栏是打开的。您需要确保这三个都设置为None。

#4


26  

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”属性以“推断”

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的大小同时也可以模拟状态栏(或其他类似的模拟)

#5


4  

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),然后在名为“模拟用户界面元素”的区域中更改标记状态栏、顶部栏和底部条的字段。你可能需要点击这个小三角形使它们可见。

#6


1  

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拖到新的然后删除旧的。

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).

它为我解决了问题,但是是的,我认为苹果的接口构建器有一个潜在的问题需要解决(如果我错了,请指正)。

I'm Using XCode 4 integrated Interface builder.

我使用XCode 4集成接口构建器。

#7


0  

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,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.

我很想知道这个问题的解决办法。

#8


0  

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是您试图链接nib/xib的类名。

Just edit your class name with the correct class name and you are done ;)

只要用正确的类名编辑类名,就完成了;)