SingleContactViewController.swift 1.97 KB
Newer Older
Javier Heisekce committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//
//  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!
17 18 19 20
    @IBOutlet weak var phoneNumber: UIButton!
    @IBOutlet weak var otherPhoneNumber: UIButton!
    @IBOutlet weak var otherPhoneLabel: UILabel!
    @IBOutlet weak var phoneLabel: UILabel!
Javier Heisekce committed
21 22 23 24 25 26
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if let contact = selectedContact{
            title = "\(contact.givenName) \(contact.familyName)"
            contactFullname.text = "\(contact.givenName) \(contact.familyName)"
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
            if let phones = contact.phoneNumbers.first {
                let phoneTitle :String  =  CNLabeledValue<NSString>.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<NSString>.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
Javier Heisekce committed
45 46 47 48
                }
            }
        }
    }
49 50 51 52
    
    @IBAction func callButton(_ sender: Any) {
    }
    
Javier Heisekce committed
53
}