Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> iOS

Đổi màu chữ Navigation Bar trong iOS

Đặt titleTextAttributes cho UINavigationBar.appearance() trong AppDelegate.didFinishLaunchingWithOptions:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  let textColor = [NSAttributedString.Key.foregroundColor: UIColor.green]
  UINavigationBar.appearance().titleTextAttributes = textColor
  return true
}

Áp dụng cho toàn app. Có thể dùng NSAttributedString.Key.font để đổi font chữ title.