[英]UINavigationBar won't set title text attributes
我試圖將我的應用程序標題文本顏色設置為白色,但是當我嘗試設置titleTextAttributes時,似乎沒有任何作用。
我還設置了其他外觀屬性,例如背景色和淡色。 但是NSAttributedString.Key.foregroundColor似乎無法正常工作。 我已經仔細檢查了文檔,以確保其采用UIColor,並且仍然似乎設置正確,沒有任何結果。 以下是我的AppDelegate供參考。
//Set the window as the visible view.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
// Make the view controller default the homeController.
window?.rootViewController = UINavigationController(rootViewController: HomeController())
//Customise navBar appearance
let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.isTranslucent = false
navBarAppearance.barTintColor = .backgroundLightBlack
navBarAppearance.tintColor = .seaFoamBlue
//This is the line that doesnt work :(
navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
找到了答案! 萬一有人碰到這個。
我正在使用preferredsLargeTitle = true導航欄。
為了設置這種樣式的標題文本屬性,您需要LargeTitleTextAttributes,它的設置與常規標題屬性完全相同,但是具有largeTitleTextAttributes屬性,例如:
navBarAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.