3

1. How can I increase the hight of my navigation bar just like Apple did for the iMessage app:

enter image description here

2. How do they make the navigation bar expand when the titleView is clicked to look like this:

enter image description here

I've tried creating a larger titleView, but it just gets clipped to the bounds of the default navigation bar height. How are they able to achieve this? Also, my view controllers are embedded in a navigation controller programmatically.

Nathan
  • 949
  • 8
  • 19
  • Possible duplicate of [Custom height for UINavigationBar or alternative of UINavigationBar](https://stackoverflow.com/questions/35680853/custom-height-for-uinavigationbar-or-alternative-of-uinavigationbar) – Mars Sep 14 '18 at 00:31
  • Possible duplicate of [How can I change height of Navigation Bar Swift 3](https://stackoverflow.com/questions/40751366/how-can-i-change-height-of-navigation-bar-swift-3) – Naresh Sep 14 '18 at 05:54
  • Hey! have you got a solution for this? I am trying to implement something similar and looking for one – Raghav7890 Sep 18 '19 at 10:36

3 Answers3

0

Unsure if you've just embedded Navigation into the app... or set this up programatically.

You'll need to add your navBar as a sort of "IBOulet", and then modify it's height based on an function/action/etc.

Say when you click "name button"; then something akin to "mainNavBar.heightAnchor.constant = 400" (where 400 is the new height).

Or if you've set this up manually, and have a auto layout constraint on the height of your nav bar, then you could set that up as a IBOutlet; and access it easier.

It would help if you posted some of your code, or atleast how you've set this up.

  • My view controller is embedded in a navigation controller programmatically on the apps start, and I'm pretty sure you can't change the navigation bar height constraint constant. – Nathan Sep 14 '18 at 00:47
0

Use navigation view instead of navigation bar or use custom view on viewDidLoad function hide navigation bar and show your custom view

Gal
  • 197
  • 1
  • 12
Anil Kumar
  • 1,830
  • 15
  • 24
0

Use this class for navigation bar height :

   import Foundation
    import UIKit

    class NavigationBar: UINavigationBar {

        //set NavigationBar's height
        //For iphonex, I recommended to set the minimum height to 88 or higher.
        var customHeight : CGFloat = 100

        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)


            translatesAutoresizingMaskIntoConstraints = false


        }

        override func sizeThatFits(_ size: CGSize) -> CGSize {

            return CGSize(width: UIScreen.main.bounds.width, height: customHeight)

        }

        override func layoutSubviews() {
            super.layoutSubviews()

            self.tintColor = .black

            frame = CGRect(x: frame.origin.x, y:  0, width: frame.size.width, height: customHeight)

            // title position (statusbar height / 2)
            setTitleVerticalPositionAdjustment(-10, for: UIBarMetrics.default)

            for subview in self.subviews {
                var stringFromClass = NSStringFromClass(subview.classForCoder)
                if stringFromClass.contains("BarBackground") {
                    subview.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: customHeight)
                    subview.backgroundColor = .yellow

                }

                stringFromClass = NSStringFromClass(subview.classForCoder)
                if stringFromClass.contains("BarContent") {

                    subview.frame = CGRect(x: subview.frame.origin.x, y: 20, width: subview.frame.width, height: customHeight - 20)


                }
            }
        }


    }
NavinBagul
  • 741
  • 7
  • 24