Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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;

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top