Search This Blog

Monday, October 24, 2016

iOS Swift. Change background color of Navigation Bar

In Navigation Bar we can change color for three items:
  1. Background color of Navigation Bar
  2. Color of items in Nvaigation Bar (buttons)
  3. Color of title of Navigation Bar
To change background color of Navigation Bar we will use UIApperance API
All code must be placed in AppDelegate.swift file in method didFinishLaunchingWithOptions
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: 
        [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        // get appearance object
        let navigationAppearance = UINavigationBar.appearance()
        
        // change color of navigation bar background
        navigationAppearance.barTintColor = UIColor.red
        
        // change color of navigation bar items (buttons)
        navigationAppearance.tintColor = UIColor.white
        
        // change color of navigation bar title
        navigationAppearance.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white];
        
        return true
    }
    
}

Results




9 comments:

  1. This is a fantastic article! Thank you very much. These suggestions are desperately needed. The in-depth description is quite helpful. Seeing how you write was quite motivating. Best Custom Websites

    ReplyDelete
  2. Thank you very much for drawing my notice to this. Your blog is jam-packed with useful facts. Until I read that, I would have no idea. I'll come back for more fantastic material.
    Best wishes, and good luck.
    Web Design USA

    ReplyDelete
  3. Good content. I was looking for this type of content. Saved my time for further search.
    You should always provide that type of content. I appreciate your determination to give the students a good title.Custom Designed Websites

    ReplyDelete
  4. Thank you so much for your post; it has provided us with an excellent idea.
    SEO Firm USA

    ReplyDelete