Can't Change Height of NavigationBar in Naviga

2019-03-07 00:21发布

I have a NavigationController extending from a master TabBarController and extending a ViewController and VC extends to 2x TableView (so, TabBar -> NavigationController -> ViewController -> 2xTableView[with .xib] ). I had to add Navigation Bar to the Navigation Controller to make it work in the viewController, thus works in both tableviews (because I use Instagram-style swipe by using PageMenu). Now, I can see the navigation bar. (Please note that I had to uncheck Translucent on navigation bar on Storyboard to make it visible)

However, it's quite wide, so I am trying to narrow the height. I have tried several answers that I've found online, but no luck for me. First, I tried adding constraints to Navigation Bar (in NavCont) but, when I click on the constraints, everything is disabled (...but for example, when I change the colour of Navigation Bar from storyboard, it works.)

enter image description here

Also, in my ViewController (where I link to TableView using this code), so I can use these and customise Navigation Bar, however when I try

// These works
self.title = "GLOBAL"      
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor()]

// Neither works for Height
self.navigationController?.navigationBar.frame.size.height = 200
self.navigationController?.navigationBar.frame = CGRectMake(0, 0, 320, 64)
self.navigationController?.navigationBar.frame.origin.y = -50

The height of Navigation Bar I want to achieve (and achieved for another UIView, by simply dragging Navigation bar to view on Storyboard):

enter image description here

This is how it looks

enter image description here

1条回答
唯我独甜
2楼-- · 2019-03-07 00:54

achieved for another UIView, by simply dragging Navigation bar to view on Storyboard

Yes, but that's the difference - all the difference in the world. You can do anything you want with your navigation bar. But the height of the navigation bar owned and vended by a UINavigationController is not up to you. It is not your navigation bar and you should abandon all hope of changing its size; the navigation controller is in charge, not you.

查看更多
登录 后发表回答