[ iOS / Swift ] 如何更改導覽列 (Navigation Bar) 的返回按鈕 (backBarButtonItem) 標題與圖片
實作:
1. 更改返回按鈕 (backBarButtonItem) 標題:
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "測試專案"
let barButtonItem = UIBarButtonItem(title: "返回", style: .plain, target: self, action: nil)
navigationItem.backBarButtonItem = barButtonItem
}
2. 更改返回按鈕 (backBarButtonItem) 圖片:
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "測試專案"
let barButtonItem = UIBarButtonItem(title: "返回", style: .plain, target: self, action: nil)
navigationItem.backBarButtonItem = barButtonItem
let image = UIImage(named: "backBarButtonImage")
let barAppearance = UINavigationBarAppearance()
barAppearance.setBackIndicatorImage(image, transitionMaskImage: image)
navigationController?.navigationBar.standardAppearance = barAppearance
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let image = UIImage(named: "backBarButtonImage")
let barAppearance = UINavigationBarAppearance()
barAppearance.setBackIndicatorImage(image, transitionMaskImage: image)
UINavigationBar.appearance().standardAppearance = barAppearance
return true
}
留言
張貼留言