Joey Clover
Joey Clover

Reputation: 776

Full customisation of UINavigationBar

I'm currently building an iOS Application for a client and have hit a pretty huge roadblock. I mean, I could write my own UINavigationBar and such but that would cause a lot of issues further down the road.

I have tried everything in my knowledge so far and have spent several hours searching for a solution (overriding the CALayer, using CoreGraphics and pretty much everything else ) and I get the same result. No matter how hard I try to remove the background of the UINavigationBar, it still shows a white background with slight translucency.

I need to have a lot of customisation on the navigation bar (I.E having a gradient going from "blackColor" to "clearColor" and I can't do that if the background of the Navigation Bar refuses to be completely transparent. I have tried copying all of the CALayers from the UINavigationBar layer to a subview I added and it just kept crashing, even when replacing the delegates and superlayer.

I really need help with this. One of the multiple effects I'm trying to achieve are below. (The blue rectangle is not the focus of the image, it's irrelevant.)

App image

Upvotes: 0

Views: 121

Answers (2)

Mikael Hellman
Mikael Hellman

Reputation: 2724

To get it completely transparent:

(UINavigationBar.appearance()).translucent = true
(UINavigationBar.appearance()).barTintColor = UIColor.clearColor()
(UINavigationBar.appearance()).backgroundColor = UIColor.clearColor()
(UINavigationBar.appearance()).setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
(UINavigationBar.appearance()).shadowImage = UIImage()

EDIT: Using iOS 8.3 looking like this:

enter image description here

Or am I missing something?

Upvotes: 1

PDice30
PDice30

Reputation: 219

You are referring to the top Navbar with the back button and Save button right? I'm just confused as to what the blue box on the image is in reference too.

Anyways, this is an extremely hacky approach but could work:

Set the UINavigationBar's alpha to 0. The Back button and Save button will probably also disappear but you could just add labels to the View Controller at the top in the exact same place. The button's should still be functional even though they are "invisible" but the user will still think they are touching them.

Again, very hacky, but you are free to play with the top part of the View then. I'm sure there's a better way to do this but I'm not near a computer with XCode at the moment and can't test it out, and this fix may not even work but I thought I'd offer up a possible temporary solution.

Upvotes: 0

Related Questions