Skip to content

Instantly share code, notes, and snippets.

@woodycatliu
Created March 29, 2021 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodycatliu/1e5d6302801fd753edbe8e7e2091af24 to your computer and use it in GitHub Desktop.
Save woodycatliu/1e5d6302801fd753edbe8e7e2091af24 to your computer and use it in GitHub Desktop.
/*
更改 navigationBar 字體顏色
方法很多種,
只特別記錄一種萬用的
*/
func setNavigationBar() {
// 完全全黑
if #available(iOS 13.0, *) {
let barAppearance = UINavigationBarAppearance()
// 更改背景色
barAppearance.backgroundColor = .blue
// 更改字體顏色
barAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.blue]
navigationController?.navigationBar.standardAppearance = barAppearance
} else {
// 更改字體色
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navigationController?.navigationBar.barTintColor = .black
// 將被透明效果關閉
navigationController?.navigationBar.isTranslucent = false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment