skip to Main Content

I want to change the height of my UINavigationBar and add a title using XCode6…This navigation bar is a separate object I placed inside of a view controller on the storyboard. Why cant I change the title or stretch it from the editor? It would be so awesome if i could just do that…but I CANT! Can somebody please point me in the right direction for how to do this programmatically in Swift? Is it best practice for this code go in the viewDidLoad? Also…is it best practice for me to even put a UINavigationBar on a View Controller? What is the advantage of using a UINavationContoller versus scrapping together my own version which I’m doing. It’s really easy to just put buttons on a navigation bar….why would I put a bar button item? It seems like the easiest thing to do is create a a nice title bar as an image in photoshop and put buttons on top of it in the editor, rather than wrestle with Interface Builder objects…am I wrong?

Sorry about ranting this is not a good question…maybe the question should be…Should I make a navigation bar in photoshop and put buttons on it instead of deal with navigation objects? I only use simple push segues with buttons for my navigation right now.

2

Answers


  1. If you want a very custom look, you have to make your own. Based on what you want (custom height) — check this out Is there a way to change the height of a UINavigationBar in Storyboard without using a UINavigationController?

    The advantages of the built in one are:

    • You get iOS look and feel with no code
    • The back buttons are filled in
    • You get access to it easily in all shown view controllers
    Login or Signup to reply.
  2. In a navigation interface, a navigation controller owns its
    UINavigationBar object and is responsible for managing it. It is not
    permissible to change the navigation bar object or modify its bounds,
    frame, or alpha values directly. However, there are a few properties
    that you can modify

    More here: apple documentation on customizing the nav bar

    You can use the UINavigationItem navigationItem property in UIViewController to customize your UINavigationBar.

    // In ViewController
      self.navigationItem.titleView = myTitleLabel;
      self.navigationItem.rightBarButtonItem = myIcon;
      self.navigationItem.leftBarButtonItem = myBackIcon;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search