PhoneNumberView.swift
3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// PhoneNumberView.swift
// InterQR-Internship
//
// Created by Дмитрий Тимофеев on 31.05.2022.
//
import UIKit
import CoreTelephony
class PhoneNumberView: UIView {
var containerPickerView: UIView = {
var view = UIView()
view.backgroundColor = .systemRed
return view
}()
var titleButton: UIButton = {
var obj = UIButton()
obj.setTitle("Select your country", for: .normal)
obj.setTitleColor(UIColor(red: 50/255, green: 55/255, blue: 85/255, alpha: 1), for: .normal)
obj.titleLabel?.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 18)
obj.titleLabel?.textAlignment = .center
return obj
}()
var dividingLineView: UIView = {
var view = UIView()
view.backgroundColor = UIColor(red: 246/255, green: 246/255, blue: 246/255, alpha: 1)
return view
}()
var phoneNumberPicker: UIPickerView = {
var picker = UIPickerView()
return picker
}()
var selectButton: UIButton = {
var button = UIButton()
button.backgroundColor = UIColor(red: 2/255, green: 115/255, blue: 185/255, alpha: 1)
button.clipsToBounds = true
return button
}()
var selectLabel: UILabel = {
var label = UILabel()
label.text = "Select"
label.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16)
label.textColor = .white
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
layout()
setup()
backgroundColor = .white
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func layout() {
self.backgroundColor = .white
addSubview(titleButton)
addSubview(dividingLineView)
addSubview(phoneNumberPicker)
addSubview(selectButton)
selectButton.addSubview(selectLabel)
titleButton.snp.makeConstraints { make in
make.top.equalToSuperview().offset(20)
make.leading.trailing.equalToSuperview()
}
dividingLineView.snp.makeConstraints {
$0.left.right.equalToSuperview()
$0.height.equalTo(1)
$0.top.equalTo(titleButton.snp.bottom).offset(22)
}
phoneNumberPicker.snp.makeConstraints {
$0.left.right.equalToSuperview().inset(5)
$0.top.equalTo(dividingLineView.snp.bottom).offset(20)
}
selectButton.snp.makeConstraints {
$0.right.equalToSuperview()
$0.left.equalToSuperview()
$0.bottom.equalToSuperview()
$0.height.equalTo(70)
$0.top.equalTo(phoneNumberPicker.snp.bottom).offset(20)
}
selectLabel.snp.makeConstraints {
$0.centerX.equalTo(selectButton.snp.centerX)
$0.top.equalTo(selectButton.snp.top).offset(20)
}
}
}
extension PhoneNumberView {
func setup() {
let countryCode: String
if let carrier = CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.first?.value,
let code = carrier.isoCountryCode?.uppercased() {
countryCode = code
} else {
countryCode = "USA"
}
phoneNumberPicker.selectRow(0, inComponent: 0, animated: true)
phoneNumberPicker.subviews[1].backgroundColor = .clear
}
}