不能在 IB 中调整 UIView 的大小

可能是一些简单的东西,但是我不明白为什么我不能在 xib 中调整 Interface Builder 的大小。

我在 xcode 中创建了一个新的视图 XIB,在大小检查器中,宽度和高度被禁用,并且灰度为320 × 460。这很奇怪,因为我可以更改其他两个视图的大小(与另外两个选项卡栏项相关联)。

我不知道这是否有什么关系,但我最近更新了 sdk 到3。

谢谢!

45431 次浏览

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.

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.

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.

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:

#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

- (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);

I'm using IB 3.2.5

I'd love to know of a little fix for this one.

I've noticed that the UIView automatically created when creating the xib file cannot be resized from the sizing panel or the edge handles.

All I did was to add another UIView and dragged everything from my old UIView to the new one then deleted the old one.

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.

As at Xcode 4.2, iOS 5.0.1, the default simulated metrics include simulating the 'size' attribute of UIViewControllers to '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)

In order to achieve that in XCode 4.6.3/5.0.2 you need to follow the screenshot below:

  1. Under 'File Inspector' -> untick Use Auto Layout
  2. Click on Attributes Selector & Choose Freeform for Size

This is needed when creating a headerView for a tableView

enter image description here

I sorted it out in a different way...

open your xib with your favourite text editor and edit this line

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

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

enter image description hereIn storyboard select the UIVIew and go to the attributes inspector change the UIVIew size to "FreeForm" instead of "Inferred"

In Xcode 13

Storyboard -> Attribute inspector -> Size -> Freeform

enter image description here