Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the color of iOS Navigation Bar

I'm trying to change the color of my navigator bar but I found that it's only impossible if the navigator is the root one.

I'm trying this:

self.navigationController?.navigationBar.translucent = true  self.navigationController!.navigationBar.barTintColor = UIColor.blueColor() 

All my Viewcontrollers are related to navigator controllers. However nothing is changed. In fact I tried to make the same things from storyboard but it works only if I'm in the first navigator.

I tried to read everything related to this problem but found nothing

I could add any item to the navigator bar like this

let HomeImage = UIImage(named: "home")!     let Home : UIBarButtonItem = UIBarButtonItem(image: HomeImage,  style: .Plain, target: self, action: "home:")     navigationItem.rightBarButtonItem = Home 
like image 582
Anthony Shahine Avatar asked Oct 08 '16 10:10

Anthony Shahine


People also ask

How do I change the color of my status bar on my Iphone?

Go to the Storyboard. Select the View and in the Attributes Inspector change the Background Color to Light Gray. Build and Run the Project. The default style of the status bar is dark content.

Can you change Iphone navigation bar?

A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.


1 Answers

In fact, i found that the solution was to use in the AppDelegate.siwft :

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {     // Override point for customization after application launch.     UINavigationBar.appearance().barTintColor = UIColor(red: 0, green: 0/255, blue: 205/255, alpha: 1)     UINavigationBar.appearance().tintColor = UIColor.whiteColor()     UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]      return true } 

and then in each view controller, that we need another background color or something else

  1. the segue should be different than "show"

  2. use the func viewWillAppear

     override func viewWillAppear(animated: Bool) {      super.viewWillAppear(animated)      self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()      self.navigationController?.navigationBar.tintColor = UIColor.blueColor()      self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blueColor()] } 
like image 137
Anthony Shahine Avatar answered Oct 08 '22 01:10

Anthony Shahine