如何更改 CNContactPickerViewController 导航栏的颜色?
How to change color of navigation bar of CNContactPickerViewController?
我想更改 CNContactPickerViewController
上显示的导航栏的颜色。
我已经尝试了下面的代码,但是它不起作用。
let contactPicker = CNContactPickerViewController()
// let searchController = UISearchController()
contactPicker.delegate = self
contactPicker.modalPresentationStyle = .fullScreen
// UISearchBar.appearance().text = "SEARCH".localized
// contactPicker.navigationController?.isNavigationBarHidden = true
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = .white
contactPicker.displayedPropertyKeys =
[CNContactPhoneNumbersKey, CNContactEmailAddressesKey]
contactPicker.predicateForEnablingContact = NSPredicate(format: "emailAddresses.@count > 0 || phoneNumbers.@count > 0")
present(contactPicker, animated: true)
您可以通过以下方式更改导航栏颜色:
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().backgroundColor = .blue
这将更改整个应用程序的颜色,因此您可以在显示控制器之前更改颜色,并在控制器关闭时将其更改回原始颜色
如果您想更改 navigationBar 中文本的颜色,只需将这些行添加到 willConnectTo 方法中 SceneDelegate 文件:
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = .orange
UINavigationBar.appearance().tintColor = .yellow
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.purple]
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.purple]
我想更改 CNContactPickerViewController
上显示的导航栏的颜色。
我已经尝试了下面的代码,但是它不起作用。
let contactPicker = CNContactPickerViewController()
// let searchController = UISearchController()
contactPicker.delegate = self
contactPicker.modalPresentationStyle = .fullScreen
// UISearchBar.appearance().text = "SEARCH".localized
// contactPicker.navigationController?.isNavigationBarHidden = true
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = .white
contactPicker.displayedPropertyKeys =
[CNContactPhoneNumbersKey, CNContactEmailAddressesKey]
contactPicker.predicateForEnablingContact = NSPredicate(format: "emailAddresses.@count > 0 || phoneNumbers.@count > 0")
present(contactPicker, animated: true)
您可以通过以下方式更改导航栏颜色:
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().backgroundColor = .blue
这将更改整个应用程序的颜色,因此您可以在显示控制器之前更改颜色,并在控制器关闭时将其更改回原始颜色
如果您想更改 navigationBar 中文本的颜色,只需将这些行添加到 willConnectTo 方法中 SceneDelegate 文件:
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = .orange
UINavigationBar.appearance().tintColor = .yellow
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.purple]
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.purple]