views:

431

answers:

3

Hello all,

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.

Anyone having a solution?

Tnx in advance.

+1  A: 

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.

Tim
Is this a new problem, becoz I havent faced this issue before though I was using the same method.
rkb
It may be a new problem to you, but it's always been this way. Perhaps it is the first time you've created a view without a status bar, inadvertently or not.
mikestew
+2  A: 

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;
intregus
+1  A: 

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.

Dirk Thannhäuser
+1, I'm just getting started with iPhone and Objective-C dev, following the tutorial containing that example. I was scratching my head for a while, but this worked perfectly!
Andy E