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

When I developed a view based project in Xcode, My view works fine. But when I use a window based project, create a view myself and try to add it as a subview to the window, it gives me a white bar at the bottom. I have never encountered this problem before, but this is my first time encountering it.

+2


source to share


4 answers


What is most likely happening is that you add a view size suitable for using the status bar in a window that is sized to include the status bar.

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



But since you're adding to a window that spans the full 480 pixels of the screen, I'm guessing your view is just too short. Try changing the height of the view or setting its y-offset.

+1


source


you always set the size of the view by getting permission from the 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 the screen resolution may change, as it will with the new iPhone. 4.

The funny thing is, even the Apple HelloWorld iPhone example got a 20px error without displaying the frame frames correctly.

+4


source


In case anyone needs to know, the code for offset source would look something like this:

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

      

+2


source


If you are using the interface builder, you can click on it, navigate to the attribute pointer, and change the status bar to none. Then you just need to adjust the height of the view in the size inspector to 480.

0


source







All Articles