Search code examples
iphonecocoa-touchxcode4

UIView positioning in IB of Xcode 4


enter image description here

Consider the screen shot above. The UIView is positioned too much to the top causing the upper test string to be partially off and there is a gap shown at the bottom screen. The screen shot also shows its corresponding positioning values in IB : x = 0 and y = 20. So there is actually an offset (y = 20) default to clear the top status bar. But still the status bar shown covers part of the UIView.

The x, y entry is greyed out, so it seems not possible to change its values. Have spent quite some time but still not able to solve this seemingly easy problem. Hope that somebody who is familiar with this could give some hints on how this should be done.

Update :

Have done it in code as suggested. It seems to work ok. If you find any errors please let me know ...

- (void)viewDidLoad
{
CGRect  position_and_size;
CGPoint cg_point;
CGSize  cg_size;

[super viewDidLoad];

// setup after loading the view from its nib.

NSLog(@" --- Screen loaded --- ");

cg_size.width  = 320;
cg_size.height = 460;

cg_point.x =  0;
cg_point.y = 20;

position_and_size.origin = cg_point;
position_and_size.size   = cg_size;


[[self view] setFrame : position_and_size];

}

.

The following is the latest screen shot :

screen shot


Solution

  • The problem is that you're placing a view that's 460 pixels high at {0,0} in a window that's 480 pixels high. The first 20 pixels of your view therefore ends up under the status bar, and the view fails to cover the bottom 20 pixels of the window. You can fix it in any of the following ways:

    • Change the autoresize options so that the view's size will be automatically adjusted to fill the window.

    • Resize the view to match the window's bound, either in code or in IB.

    • Position the view at {0,20}, either in code or in IB.