【问题标题】:How to change color of navigation bar of CNContactPickerViewController?如何更改 CNContactPickerViewController 导航栏的颜色?
【发布时间】:2021-10-21 03:32:48
【问题描述】:

我想更改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)

【问题讨论】:

    标签: ios swift uinavigationbar contacts


    【解决方案1】:

    如果您想更改 navigationBar 中文本的颜色,只需将这些行添加到 SceneDelegate 文件中的 willConnectTo 方法:

     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]
    

    【讨论】:

      【解决方案2】:

      您可以通过以下方式更改导航栏颜色:

      UINavigationBar.appearance().tintColor = .white
      UINavigationBar.appearance().backgroundColor = .blue
      

      这将为整个应用程序更改它,因此您可以在显示控制器之前更改颜色,并在控制器关闭时将其更改回原始颜色

      【讨论】:

      • 我有使用代码,但它改变了搜索栏背景...
      • 你可以玩:UISearchTextField.appearance()UISearchBar.appearance(),直到你得到你想要的结果
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多