When I hide my navigation bar I end up with some space under it, it looks like the status bar is twice as big as it should be.
In the image the red line is just touching where the statusbar/navigation bar ends.
My VC is contains a scroll view that is spaced 0 to the edges and spaced 0 to the top layout guide.
Why is the navigation bar not hiding completly? I thought that if you hide the navigation bar you would end up with a 20px statusbar showing only.
I could space my scrollview to be +20 from the top view but that seems a bit hacky.
Look for Extended Edges in attribute inspector of the view controller and uncheck Under Top Bars.
I am trying to place all elements of a navigationBar in the vertical center, but I don't know how to do it?
The gray part above the yellow is the navigationBar. As we can see the title and other elements of the navigationBar are not vertically centered.
How can I do that ?
My Code so far :
let navigationItem = UINavigationItem()
navigationItem.title = sTitle;
navigationBar.frame = CGRectMake(0,0,screenwidth, 50);
navigationBar.titleTextAttributes = [ NSFontAttributeName: titleFont, NSForegroundColorAttributeName: UIColor.blackColor()]
self.view.addSubview(navigationBar);
You can center all your elements ,if you hide the status bar,which can be achieved by add the following to your Info.plist:
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
And your ViewController would look like this:
You can see more ways to hide the status bar in this link :hide Status bar
Firstly try to use native approach to set navigation bar title like:
self.title="Test title"
Or if you would like to have custom font try this :
self.navigationController.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "CustomFont", size: 15)!]
As is mentioned in the comments, the reason these elements are not vertically centered is the fact that the status bar is shown, which reserves 10 points at the top of the navigation bar. It's just not easily visible because it's using the light content style. If your battery was low or charging you'd see the battery at the top right.
You'll need to remove the status bar which will decrease the height of your navigation bar. As there are different ways to hide the status bar based on project setup and context I won't instruct how to remove the status bar, but information on how to do so is widely available.
Once that extra space is removed your items will be vertically centered.
The navbar text/items will never look centered, the way you are displaying things. Technically they are already centered in the Nav bar, but the nav bar manages the centering, and keeps all elements constrained to the lower edge of the nav bar.
The status bar needs 20px. The nav bar should be 44px in height. The top of the nav bar should be constrained to the Top Layout Margin, NOT 0 to the top view boundary itself. The reason for this is that ios removes the status bar (actually the top 20px of whatever displays in portrait mode) when the device is flipped to landscape mode. If your nav bar is 44px, switching the device to landscape mode will show you that the text is correctly centered vertically.
My suggestion for you to see all of this is to create a small view above the nav bar. Make the view 20px high, constrain it to the View.Top (NOT to the margin), and set the background or tintcolor to bright green or something. Then set your nav bar to 44px, constrain it to the Top Layout Margin Guide (NOT to the bottom of the status view you just created, and NOT offset from the View.Top Boundary).
Then when you flip the device back and forth, you'll see that your text is always centered within the nav bar, and the status bar will come and go above the nav bar.
PS. Do this in the storyboard first, it's easiest that way.
Using storyboard and Swift, I have a view controller which has two elements on it. A UITextField, and a UIView, which I use merely to give a colored border to the UITextField. The UITextField is a child of the UIView. See:
The problem I am having is that despite having set the top bar and bottom bar simulated metrics attributes to Opaque Navigation Bar and Opaque Tab Bar respectively, See:
When the app builds and runs the top of the UIView is always underneath the nav bar. My over all feeling is that this is somehow a constraints issue but I have not been able to find the solution to it. How do I set the constraints so that the UIView is always immediately underneath the nav bar, and the bottom of the view is always just on top of the tab bar?
Select your UIView in storyboard and assign constraints to the top margins and to bottom margins. There is a 'Pin' button you use to do this that looks something like a Tie-Fighter ship in Star Wars, it is located at the bottom right of your storyboard view.
This will set margins to stretch to top and bottom always.
That is what the layout guides are for. Pin the top to the Top Layout Guide and the bottom to the Bottom Layout Guide. The guides will always move to adjust for any top and bottom bars.
I have a UIViewController. I am designing the screen for iPhone 5s. I have a UIImageView & I am giving top space to container of 20. I also have UINavigationBar at top.So the space given of 20 is not enough. UIImageView is hidden behind the UINavigationBar. I can resolve this issue by giving much space from top. But in that case at design time my UI will not look proper. So is there any way by which space from UINavigationBar is automatically calculated?
In Attribute Inspector set Top Bar to Translucent Navigation Bar like this
then set Top Space of imageView to Top Layout Guide like,
set navigation bar type as opaque Navigation Bar so it will opaque that much space from your view controller and show your view content after navigation bar space they will not hide inside of navigation bar.
but if you set navigation bar type as Translucent Navigation bar then your content will hide inside of navigation bar so set "Opaque Navigation Bar" type. no need to do any other stuff for that.
I hope it will help you!
I have a plain UITableView displayed in a UIView class.
When scrolling to top or bottom it displays white padding.
There are no header\footer views to this table.
This problem occurs only in iOS7.
Here is a screen shot of how it looks
[You can see the white rectangle above digit '1'. I have the same at the bottom]
So far I have tried:
1. tweaking the contentInsets' - it worked, BUT it disabled the ability to scroll the table.
2. UnCheck the "Top Bars", "Bottom Bars" and "Opaque Bars" attribute in IB - Didn't help.
and other stuff that where offered in other posts.
Any idea?