How to give automatically top space to navigation bar in ios? - ios

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!

Related

Why is my UINavigationBar hidden behind the top navigation bar in iMessage?

I have an iMessage extension and I want to make a UI with a UINavigationBar on top. I made a UINavigationBar via a UINavigationController in the storyboard. The bar looks fine in compact presentation style but when I switch to expanded it gets hidden behind the top bar in iMessage. I have had this issue in the past and resolved it by setting the top space to top layout guide to 0. However, I don't think I can constrain a UINavigationBar. Any advice?

Swift ios odd space when hiding navigation bar

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.

Can't get translucent navigation bar on tableviewcontroller. Works fine with view controller and tableview

I've got a gradient background that I want to show through both the navigation bar and the tab bar. I have them set to "translucent black". If I create a ViewController and put a TableView on it, this works perfectly. However, I can't get it to work properly with a TableViewController. The tab bar works fine, but the navigation bar ends up black. If I turn off "Adjust Scroll View Insets", then the navigation bar looks the way I want it, but the top half of the first table view row gets cut off (see examples). The gradient is on the background view. The background colour of the tableview is clear.
Is there any way to get the same effect on a TableViewController? Do I need to somehow make the heading or first row of the tableview be the background that goes under the nav bar?
ViewController with TableView added:
TableViewController with "Adjust Scroll View Insets" ON:
TableViewController with "Adjust Scroll View Insets" OFF:
After doing a test I think you'd need:
Adjusts Scroll View Insets ON
Extend Edges - Under Top Bars ON
No. 1 allow the UITableView to cover the entire screen (including under the navigation bar) and No. 2 adds a space at the top of the UITableView content so that the content is not hidden under the navigation bar.
I ran into a similar issue trying to set a full screen background on a static table view controller with a clear navigation bar. I solved it by using a backgroundView on my tableView instead of setting backgroundColor. For example:
myTableView.backgroundView = UIImageView(image: UIImage(named: "backgroundImg.png"))
I set my navigation bar to clear, but you could style that however you like:
navigationController?.navigationBar.backgroundColor = UIColor.clear
I also had to set Extend Edges - Under Top Bars ON

Segmented control in Navigation bar

I need to put segmented control into navigation bar below the title and other buttons. How do I make this? Everything I found so far says you can't increase the height of navigation bar without hacks. Is it even possible?
https://drive.google.com/file/d/0B2fViGVp6nhhOEdJSU0zeWZiS1U/view?pli=1
Why don't you put both of them separately? On top navigation bar and below that UISegmentControl.
Just make sure background for UISegmentControl should be matched and aligned with UINavigation bar.
Hope that helps.

UISearchBar and UINavigationBar from navigation controller disappearing when searching

I have a UINavigationController with a UISearchBar right under the UINavigationBar. When I click in the search bar, the text and buttons on the UINavigationBar disappears, but the blank white bar still stays. I think this is because it is a navigation controller and so the navigation bar can disappear. In addition, when I start typing, the search bar disappears, but I can still type. My question: is there a way to either make the entire navigation bar disappear when I start searching or make the text on the navigation bar stay while searching, and how do I ensure the search bar does not disappear? Thanks.
self.searchController.hidesNavigationBarDuringPresentation = NO;
Figured it out. In the storyboard, I had to click on the little icon on the bottom, third from the left, then "resolve auto layout issues." Autolayout must be off for this to work

Resources