rkb
rkb

Reputation: 11231

See a white band at the bottom of screen while adding view to window programmatically in iPhone?

When I developed a view based project in Xcode, My view works fine. But when I use a window based project and create a view on my own and try adding it as a subview to window, it gives me a white band at the bottom. I never faced this issue before but facing it first time.

Upvotes: 2

Views: 1298

Answers (4)

Maleck13
Maleck13

Reputation: 1739

If you're using interface builder you can click on the view, go to attribute inspector and change status bar to none. You then simply need to adjust the height of the view in the size inspector to 480.

Upvotes: 0

Dirk Thannhäuser
Dirk Thannhäuser

Reputation: 283

you shoud always set the View Size by getting the resolution from UIScreen

UIView *controllersView = [myViewController view]; // get the view
[controllersView setFrame:[[UIScreen mainScreen]applicationFrame]]; // set the Framesize

This automatically sets the origin to x=0 and y=20. Keep in mind, that you should use this method instead of manually setting the origin to y=20 because screen resolution can change as it will be with the new iPhone 4.

The funny thing is, that even Apple's HelloWorld Example for the iPhone has got the 20 pixels bug without setting the views Frame correctly.

Upvotes: 4

Ryan_IRL
Ryan_IRL

Reputation: 575

In case somebody needs to know, the code to offset the origin would look something like this:

CGRect frame = myController.view.frame;
frame.origin.y = 20.0;
myController.view.frame = frame;

Upvotes: 2

Tim
Tim

Reputation: 60150

Most likely what is happening is that you're adding a view sized appropriately for using a status bar to the window, whose size includes the status bar.

The iPhone's screen is 480px high, and the top 20px of that are allocated for the device's status bar (the one with the signal strength/WiFi indicator, clock, etc.). Normally, a view will be sized for the remaining 460px of the window, and if you're developing a view-based app, that's fine - that application template already provides a 320x460 root view that all your other subviews get added to.

But since you're adding to the window, which spans all 480px of the screen, my guess is that your view is just 20px too short. Try changing the height of the view, or setting its y-offset.

Upvotes: 1

Related Questions