Search code examples
swiftuinavigationbaropacityalpha

Unable to change navigation bar opacity


I am trying to style my app in the following way, however i am unable to get my navigation bar to reach this level of opacity

enter image description here

I use the following code to style the navigation bar:

unc application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    UINavigationBar.appearance().barTintColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.1)
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
}

Even with the alpha set to 0.1, i still only get the following result:

enter image description here

Is it possible to achieve such a low opacity?


Solution

  • This is the best way that I've found. You can just paste it into your appDelegate's didFinishLaunchingWithOptions method:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        // Sets background to a blank/empty image
        UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
        // Sets shadow (line below the bar) to a blank image
        UINavigationBar.appearance().shadowImage = UIImage()
        // Sets the translucent background color
        UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
        // Set translucent. (Default value is already true, so this can be removed if desired.)
        UINavigationBar.appearance().translucent = true
    
        return true
    }