RemoveAdvertView.swift
5.24 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
//
// RemoveAdvertView.swift
// browser
//
// Created by Artem Talko on 29.09.2023.
//
import UIKit
import SnapKit
final class RemoveAdvertView: GradientView {
private let appLogoImageView: UIImageView = {
let obj = UIImageView()
obj.image = .gotoweb
obj.contentMode = .scaleAspectFit
return obj
}()
let adBlockButton: UIButton = {
let obj = UIButton()
let userDefaultsAdBlockingValue = CachingManager.shared.adBlockerState
obj.layer.cornerRadius = 0.5 * 171.sizeH
obj.layer.masksToBounds = true
obj.layer.borderWidth = 2.0
obj.setBackgroundImage(.backgroundGradient, for: .normal)
obj.layer.borderColor = UIColor.white.cgColor
if userDefaultsAdBlockingValue {
obj.setImage(.adBlockOnState, for: .normal)
} else {
obj.setImage(.adBlockOffState, for: .normal)
}
return obj
}()
let removeAdvertSegmentControl: UISegmentedControl = {
let items = StringConstants.segmentedControlItems
let obj = UISegmentedControl(items: items)
obj.selectedSegmentIndex = 0
obj.layer.cornerRadius = 10
obj.backgroundColor = ColorConstants.segmentControlBackground
obj.selectedSegmentTintColor = UIColor(red: 0.349, green: 0.565, blue: 1, alpha: 1)
obj.setTitleTextAttributes([.foregroundColor: UIColor.black], for: .normal)
obj.setTitleTextAttributes([.foregroundColor: UIColor.white], for: .selected)
return obj
}()
private let leftDecorativeSquareImageView: UIImageView = {
let obj = UIImageView()
obj.image = .leftDecorativeSquares
return obj
}()
private let rightDecorativeSquareImageView: UIImageView = {
let obj = UIImageView()
obj.image = .rightDecorativeSquares
return obj
}()
let tapActionLabel: UILabel = {
let obj = UILabel()
let userDefaultsAdBlockerValue = CachingManager.shared.adBlockerState
obj.font = FontConstants.semiboldFont_24
if userDefaultsAdBlockerValue {
obj.textColor = ColorConstants.SearchbarTintBlue
obj.text = StringConstants.turnOff
} else {
obj.textColor = ColorConstants.customPink
obj.text = StringConstants.turnOn
}
return obj
}()
private let protectFromLabel: UILabel = {
let obj = UILabel()
obj.text = StringConstants.adBlockProtectFrom
obj.font = FontConstants.semiboldFont_18
return obj
}()
let adBlockTableView: UITableView = {
let obj = UITableView()
obj.backgroundColor = .clear
obj.isScrollEnabled = false
obj.separatorStyle = .none
return obj
}()
override init (frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() {
addSubview(appLogoImageView)
addSubview(adBlockButton)
addSubview(tapActionLabel)
addSubview(removeAdvertSegmentControl)
addSubview(leftDecorativeSquareImageView)
addSubview(rightDecorativeSquareImageView)
addSubview(protectFromLabel)
addSubview(adBlockTableView)
setupConstraints()
}
private func setupConstraints() {
leftDecorativeSquareImageView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.leading.equalToSuperview()
}
rightDecorativeSquareImageView.snp.makeConstraints { make in
make.bottom.equalToSuperview()
make.trailing.equalToSuperview()
}
appLogoImageView.snp.makeConstraints { make in
make.top.equalTo(safeAreaLayoutGuide.snp.top).offset(24.sizeH)
make.leading.trailing.equalToSuperview()
make.height.equalTo(34.sizeH)
}
removeAdvertSegmentControl.snp.makeConstraints { make in
make.top.equalTo(appLogoImageView.snp.bottom).offset(34.sizeH)
make.leading.trailing.equalToSuperview().inset(54.sizeW)
make.height.equalTo(34.sizeH)
}
adBlockButton.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.centerX.equalToSuperview()
make.height.equalTo(171.sizeH)
make.width.equalTo(171.sizeH)
}
tapActionLabel.snp.makeConstraints { make in
make.top.equalTo(adBlockButton.snp.bottom).offset(45.sizeH)
make.centerX.equalToSuperview()
}
protectFromLabel.snp.makeConstraints { make in
make.top.equalTo(tapActionLabel.snp.bottom).offset(44.sizeH)
make.leading.equalToSuperview().offset(44.sizeW)
}
adBlockTableView.snp.makeConstraints { make in
make.top.equalTo(protectFromLabel.snp.bottom).offset(4.sizeH)
make.leading.equalToSuperview().offset(44.sizeW)
make.trailing.equalToSuperview().offset(-32.sizeW)
make.bottom.equalToSuperview().offset(-16.sizeH)
}
}
}