CNContactViewController按钮动作

时间:2017-08-09 14:59:34

标签: ios swift swift3 contacts

我正在使用CNContactViewController。但是,我想添加一个新按钮。我该怎么做

如果您无法添加新按钮,那么如何才能获得“呼叫”按钮的操作?

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以尝试这样但我已经用于新的联系人,您可以自定义代码。

func CreateNewContact() {

    let contact = CNMutableContact()


    let unkvc = CNContactViewController(forNewContact: contact)
    unkvc.delegate = self
    unkvc.allowsEditing = true
    unkvc.allowsActions = true
    unkvc.title = "Create New Contact"
    self.navigationController?.isNavigationBarHidden = false

    self.navigationController?.navigationBar.backgroundColor = UIColor(red: 234.0/255.0, green: 34.0/255.0, blue: 39.0/255.0, alpha: 1.0)
    self.navigationController?.navigationBar.tintColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)

    Application.Delegate.setStatusBarBackgroundColor(color: UIColor(red: 198/255.0, green: 6/255.0, blue: 39.0/255.0, alpha: 1.0))


    self.navigationController?.navigationItem.hidesBackButton = true

    let rightButton: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.done, target: self, action: #selector(ShowInfotoshare.doneButtonClicked(_:)))

    self.navigationController?.navigationItem.rightBarButtonItem = rightButton


    self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]

    self.navigationController?.pushViewController(unkvc, animated: false)



}

func doneButtonClicked(_ button:UIBarButtonItem!){
    print("Done clicked")
}

如果您有任何疑问,请告诉我您的代码,以便我帮助您。

答案 1 :(得分:0)

AFAIK,名称下的按钮行(让我们称之为“通信方法”)无法修改。您无法隐藏行或单个按钮,您无法在行中添加任何内容。

此外,按钮活动/非活动状态由当前联系信息(显示在其下方)控制。

最后,请注意模拟器,因为它不提供电话呼叫服务,也不包括Mail.app,按钮状态将与真实设备完全不同。