SubscriptionView.swift
5.45 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// SubscriptionView.swift
// browser
//
// Created by Artem Talko on 24.11.2023.
//
import UIKit
final class SubscriptionView: GradientView {
let closeButton: UIButton = {
let obj = UIButton()
obj.setImage(UIImage(systemName: "xmark"), for: .normal)
obj.contentMode = .scaleToFill
obj.tintColor = .gray
return obj
}()
let shieldView: UIImageView = {
let obj = UIImageView()
obj.image = .shield
obj.contentMode = .scaleAspectFit
return obj
}()
private let gradientLayer = CAGradientLayer()
private let abvertBlockerModeLabel: UILabel = {
let obj = UILabel()
obj.text = StringConstants.advertMode
obj.font = FontConstants.semiboldFont_18
return obj
}()
let advantagesTableView: UITableView = {
let obj = UITableView()
obj.backgroundColor = .clear
obj.isScrollEnabled = false
obj.separatorStyle = .none
return obj
}()
private let claimOfferLabel: UILabel = {
let obj = UILabel()
obj.text = StringConstants.claimOffer
obj.font = FontConstants.regularFont_12
return obj
}()
private let priceLabel: UILabel = {
let obj = UILabel()
obj.text = StringConstants.price
obj.font = FontConstants.regularFont_18
return obj
}()
let subscribeButton: UIButton = {
let obj = UIButton()
obj.backgroundColor = .systemIndigo
obj.setTitle(StringConstants.subscribe, for: .normal)
obj.titleLabel?.font = FontConstants.semiboldFont_17
obj.setTitleColor(.white, for: .normal)
obj.layer.cornerRadius = 10
obj.layer.masksToBounds = true
return obj
}()
private let freeTrialLabel: UILabel = {
let obj = UILabel()
obj.textAlignment = .center
obj.font = FontConstants.semiboldFont_12
obj.text = StringConstants.freeTrial
return obj
}()
private let discountLabel: UILabel = {
let obj = UILabel()
obj.textAlignment = .center
obj.text = StringConstants.yourDiscount
obj.font = FontConstants.regularFont_12
return obj
}()
override init (frame: CGRect) {
super.init(frame: frame)
setup()
}
override func layoutSubviews() {
super.layoutSubviews()
gradientLayer.frame = subscribeButton.bounds
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() {
addSubview(closeButton)
addSubview(shieldView)
addSubview(abvertBlockerModeLabel)
addSubview(advantagesTableView)
addSubview(claimOfferLabel)
addSubview(priceLabel)
addSubview(subscribeButton)
addSubview(freeTrialLabel)
addSubview(discountLabel)
setupConstraints()
gradientSetup()
}
private func setupConstraints() {
closeButton.snp.makeConstraints { make in
make.top.equalTo(safeAreaLayoutGuide.snp.top).offset(16.sizeH)
make.trailing.equalToSuperview().inset(16.sizeW)
make.height.equalTo(24.sizeH)
}
shieldView.snp.makeConstraints { make in
make.top.equalTo(closeButton.snp.top).offset(8.sizeH)
make.leading.trailing.equalToSuperview().inset(47.sizeW)
make.height.equalTo(280.sizeH)
}
abvertBlockerModeLabel.snp.makeConstraints { make in
make.top.equalTo(shieldView.snp.bottom).offset(16.sizeH)
make.centerX.equalToSuperview()
}
advantagesTableView.snp.makeConstraints { make in
make.top.equalTo(abvertBlockerModeLabel.snp.bottom).offset(26.sizeH)
make.leading.equalToSuperview().offset(80.sizeW)
make.bottom.equalTo(claimOfferLabel.snp.top).offset(-24.sizeH)
make.trailing.equalToSuperview().offset(-86.sizeW)
}
claimOfferLabel.snp.makeConstraints { make in
make.bottom.equalTo(priceLabel.snp.top).offset(-4.sizeH)
make.centerX.equalToSuperview()
}
priceLabel.snp.makeConstraints { make in
make.bottom.equalTo(subscribeButton.snp.top).offset(-16.sizeH)
make.centerX.equalToSuperview()
}
subscribeButton.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview().inset(32.sizeW)
make.bottom.equalTo(freeTrialLabel.snp.top).offset(-16.sizeH)
make.height.equalTo(40.sizeH)
}
freeTrialLabel.snp.makeConstraints { make in
make.bottom.equalTo(discountLabel.snp.top).offset(-8.sizeH)
make.centerX.equalToSuperview()
}
discountLabel.snp.makeConstraints { make in
make.bottom.equalTo(safeAreaLayoutGuide.snp.bottom).offset(-24.sizeH)
make.centerX.equalToSuperview()
}
}
}
//MARK: Gradient
extension SubscriptionView {
private func gradientSetup() {
subscribeButton.layer.insertSublayer(gradientLayer, at: 0)
gradientLayer.colors = [UIColor(red: 0.349, green: 0.565, blue: 1, alpha: 1).cgColor, UIColor(red: 0.349, green: 0.565, blue: 1, alpha: 0.7).cgColor]
gradientLayer.locations = [0.0, 1.0]
}
}