Swift Custom NavBar Back Button Image and Text

后端 未结 12 1294
谎友^
谎友^ 2021-01-30 10:40

I need to customise the look of a back button in a Swift project.

Here\'s what I have:

Here\'s what I want:

I\'ve tried creating my own UIBarButtonItem

12条回答
  •  既然无缘
    2021-01-30 10:53

    Just in case someone need to change all Back buttons color or font with Swift5. UIBarButtonItem.appearance().tintColor = .red

    Add this to AppDelegate.swift file.

    import UIKit
    
    @main
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Override point for customization after application launch.        
        UIBarButtonItem.appearance().tintColor = .white
        UIBarButtonItem.appearance().setTitleTextAttributes([
            NSAttributedString.Key.foregroundColor: .red,
            NSAttributedString.Key.font: UIFont(name: "font_name", size: 14)!
        ], for: .normal)
    
        return true
    }
    
    }
    

提交回复
热议问题