【问题标题】:CNContactPickerViewController: contact detail back button colorCNContactPickerViewController:联系人详细信息后退按钮颜色
【发布时间】:2017-12-14 17:14:55
【问题描述】:

我链接一个简单的project 来解释我的问题。

简单来说,我有一个基于导航控制器的红色主题应用程序,我必须通过CNContactPickerViewController 从我的联系人中选择电子邮件地址。

我的问题是联系人详细信息视图的返回栏按钮(下图中的红色圆圈):它在白色背景中显示为白色,因此不可见。

如何更改默认返回栏按钮的色调颜色(仅适用于联系人详细信息视图)?

【问题讨论】:

  • 你找到如何改变色调了吗?
  • 不,对不起。如果您能找到解决方案,请回答我的问题。
  • 我不确定,但我认为使用 CNContactPickerViewController 的子类是可能的。在 viewDidLoad 中使用self.navigationController.navigationBar.tintColor = UIColor.white

标签: ios cncontact


【解决方案1】:

我没有找到改变联系人详细信息视图中的UIBarButtonItemtintColor的方法,所以我解决了白色背景中的白色条形按钮颜色的问题,恢复了@之前的默认UINavigationBarappearance 987654326@ 演示文稿并在 CNContactPickerViewController 被解除时更改回我的自定义 UINavigationBar appearance

import UIKit
import Contacts
import ContactsUI

class ViewController: UIViewController, CNContactPickerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func openContacts(_ sender: Any) {
        let contactPicker = CNContactPickerViewController()
        contactPicker.predicateForSelectionOfContact = NSPredicate(value: false)
        contactPicker.delegate = self
        setupDefualtAppearance()
        self.present(contactPicker, animated: true, completion: nil)
    }

    func setupCustomAppearance() {
        UINavigationBar.appearance().tintColor = UIColor.white
        UINavigationBar.appearance().barTintColor = UIColor(red: 175.0/255.0, green: 22.0/255.0, blue: 28.0/255.0, alpha: 1.0)
        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
        UINavigationBar.appearance().barStyle = .black
    }

    func setupDefualtAppearance() {
        UINavigationBar.appearance().tintColor = nil
        UINavigationBar.appearance().barTintColor = nil
        UINavigationBar.appearance().titleTextAttributes = nil
        UINavigationBar.appearance().barStyle = .default
    }

    func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
        setupCustomAppearance()
    }

    func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
        setupCustomAppearance()
    }

    func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) {
        setupCustomAppearance()
    }
}

link一个简单的项目来解释解决方法。

【讨论】:

  • 如果您在项目中不使用 UINavigationBar.appearance(),该解决方案将混淆整个应用程序的导航栏颜色。
  • @Argus 如果您在项目中不使用自定义 UINavigationBar.appearance(),则无需恢复默认的 iOS UINavigationBar 外观,则不需要此解决方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-30
  • 2016-10-26
  • 2020-05-08
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多