1

I have the same issue as the thread here. I can manage to make the Status Bar Visible by making the text white but this isn't my goal. I also mean to color on top of the bar, like all navigation bars do. I've been able to achieve this by adding the shapes I want with views, under layoutSubviews, however this way you can't interact or see the UINavigationItem. Code:

- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor yellowColor] setFill];
UIRectFill(rect);

This is the result:

enter image description here

This is the bast that can be achieved with drawRect:

enter image description here

And this happens if you do it under layoutSubviews:

enter image description here

As you can see, the back text, the arrow, are all lost. So I'm really looking for a way to make drawRect work! Thanks in advance for your help!

Community
  • 1
  • 1
isklikas
  • 190
  • 2
  • 16
  • You meant you want it to look like your third pic but the button doesnt show up? – Tj3n Aug 08 '16 at 11:30
  • @Tj3n Yes, but it's not just the color that I want, otherwise I would use the tint color property. The bar is meant to be a proper sketch (with a star and multiple colors in). And this is because layoutsubviews works on top of the drawRect, as the views are blocking all the visible elements (the button, the title in the main screen, everything). – isklikas Aug 08 '16 at 11:34
  • You can actually hide the `navigationBar` background, shadow and color to clear color, then add your custom view below that invisible nav bar, im doing that for custom nav bar :D i can answer in swift if you need, else can google pretty easy – Tj3n Aug 08 '16 at 11:38
  • @Tj3n Sure thing, I can use Swift too, I'd like to see the answer to check this out :) – isklikas Aug 08 '16 at 11:42

1 Answers1

1

First, set your navBar to invisible with:

navController.navigationBar.translucent = true
navController.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
navController.navigationBar.shadowImage = UIImage()
navController.navigationBar.backgroundColor = UIColor.clearColor()

Create a view in storyboard or xib and make property in the VC, then add it with:

navController.view.insertSubview(navBarView, belowSubview: (navigationController?.navigationBar)!)

After that your subview should appear behind the bar buttons and it can work normally with your custom navBarView, but remember to remove that navBarView and return the navBar to default when view disappear:

navController.navigationBar.translucent     = false
navController.navigationBar.shadowImage     = nil
navController.navigationBar.setBackgroundImage(nil, forBarMetrics: .Default)
navController.navigationBar.backgroundColor = UIColor.whiteColor()
Tj3n
  • 9,837
  • 2
  • 24
  • 35