1

My app requires the navigation bar to be more then usual size, to increase the size, I added the following class and assigned to navigation controller in story board

class CustomNavigationBar: UINavigationBar {

    override func sizeThatFits(_ size: CGSize) -> CGSize {
        return CGSize(width: UIScreen.main.bounds.width, height: 70)
    }

    override func awakeFromNib() {
        let attribtutes = [
            NSFontAttributeName: UIFont(name: "Montserrat-Light", size: 18)!,
            NSForegroundColorAttributeName: UIColor.black,
            NSKernAttributeName: 5.0
            ] as [String : Any]
        UINavigationBar.appearance().titleTextAttributes = attribtutes
        UINavigationBar.appearance().tintColor = UIColor.black
        UINavigationBar.appearance().backgroundColor = UIColor.green
    }
}

This does increase the size, however the navigation bar items are placed in the bottom. (refer the screenshot below)

enter image description here

What I am looking for is to center align the title and back button vertically. I also want to move the back button slightly to the right.

I tried multiple options but nothing seems to work. Any help on how to go about is appreciated.

Thanks.

shallowThought
  • 19,212
  • 9
  • 65
  • 112
Ibrahim Azhar Armar
  • 25,288
  • 35
  • 131
  • 207
  • Did you check this solution: http://stackoverflow.com/questions/31940352/how-to-increase-the-height-of-navigation-bar-in-xcode – Kegham K. May 12 '17 at 14:53
  • Why downvote? I hate it when people tend to do policing without even properly understanding the question. @Kegham Yes, refer my code, I did increase the size, my issue is more alignment and not height. – Ibrahim Azhar Armar May 12 '17 at 14:59
  • 2
    Yes when people don't understand the question they down vote without even understanding the issue :(. Anyway did you try doing a trick like removing the boarder of the navigation bar and adding a label under it with the same background color of the navbar. I mean make the nav bar a little smaller then add a label under it with same bg color and the title of the nav bar will look as if it is in the middle. – Kegham K. May 12 '17 at 15:09
  • 2
    This article looks like a pretty good description of how the NavBar elements get laid out, and one way to get around it: https://www.emdentec.com/blog/2014/2/25/hacking-uinavigationbar – DonMag May 12 '17 at 15:30
  • 1
    check this post http://stackoverflow.com/questions/40316352/increase-navigationbar-height/40320225#40320225 and http://stackoverflow.com/questions/40437255/add-space-from-the-top-for-navigation-title/40438244#40438244 – Joe May 13 '17 at 08:33

0 Answers0