0

Hey I am trying to add a custom view to a navigation bar. The current result is like so:

enter image description here

I initialise this navigation bar like so:

 func setupNavBar() {
        navigationController?.navigationBar.isTranslucent = false
        let navBarView = ExamCoachNavBarView(frame: CGRect(x: 0, y: 0, width: 236, height: 45))
        navigationItem.titleView = navBarView
    }

I want to move the custom view down to the bottom of the nav bar. I have tried changing the y value for the navBarView frame. This make absolutely no difference those. Regardless to what that value is the frame always stays in the same position at the top of the bar. What am I doing wrong here? How can I move the bar to the bottom of the screen?

Kex
  • 8,023
  • 9
  • 56
  • 129
  • Why do you set `y: 300`? Try with `y: 0` and for easy debug, add background color for the `ExamCoachNavBarView` – Scott.N Oct 23 '17 at 10:32
  • @Scott.N tried that. The position always remains the same. – Kex Oct 23 '17 at 10:37
  • You should add a testing background color for `navBarView` and see how to this view display on the screen and compare the height you set and height it renders. – Scott.N Oct 23 '17 at 10:39
  • I tried changing the background color of the `navBarView` but oddly it doesn't show any colour. Just those labels like the image above. @Scott.N – Kex Oct 23 '17 at 10:45
  • @Scott.N seems to be related to using a view initialized from a xib file. If I create a view programatically I can adjust the view's frame and background color. If I try to initialize from a .xib it won't work. – Kex Oct 23 '17 at 11:06

0 Answers0