// // SingleContactViewController.swift // ContactsApp // // Created by User on 3/13/20. // Copyright © 2020 jheisecke. All rights reserved. // import UIKit import ContactsUI class SingleContactViewController: UIViewController { @IBOutlet weak var contactFullname: UILabel! var selectedContact : CNContact? @IBOutlet weak var profilePic: UIImageView! @IBOutlet weak var phoneNumber: UIButton! @IBOutlet weak var otherPhoneNumber: UIButton! @IBOutlet weak var otherPhoneLabel: UILabel! @IBOutlet weak var phoneLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() if let contact = selectedContact { title = "\(contact.givenName) \(contact.familyName)" contactFullname.text = "\(contact.givenName) \(contact.familyName)" if let phones = contact.phoneNumbers.first { let phoneTitle :String = CNLabeledValue.localizedString(forLabel: phones.label! ) phoneLabel.text = phoneTitle phoneNumber.setTitle(phones.value.stringValue, for: .normal) phoneLabel.isHidden = false phoneNumber.isHidden = false } if contact.phoneNumbers.last != contact.phoneNumbers.first, let phones = contact.phoneNumbers.last { let phoneTitle :String = CNLabeledValue.localizedString(forLabel: phones.label! ) otherPhoneLabel.text = phoneTitle otherPhoneNumber.setTitle(phones.value.stringValue, for: .normal) otherPhoneLabel.isHidden = false otherPhoneNumber.isHidden = false } if let image = contact.imageData { profilePic.layer.cornerRadius = profilePic.frame.height / 2 if let imageData = UIImage(data: image){ profilePic.image = imageData } } } } @IBAction func callButton(_ sender: Any) { guard let number = URL(string: "tel://" + (selectedContact!.phoneNumbers.first?.value.stringValue)!) else { return } UIApplication.shared.open(number) } @IBAction func callSpecificNumber(_ sender: Any) { } }