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
|
//
// ConsentContentView.swift
// MullvadVPN
//
// Created by pronebird on 28/04/2021.
// Copyright © 2021 Mullvad VPN AB. All rights reserved.
//
import UIKit
class ConsentContentView: UIView {
let titleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.font = UIFont.systemFont(ofSize: 24, weight: .bold)
titleLabel.numberOfLines = 0
titleLabel.textColor = .white
titleLabel.allowsDefaultTighteningForTruncation = true
titleLabel.text = NSLocalizedString("PRIVACY_NOTICE_HEADING", tableName: "Consent", comment: "Heading.")
titleLabel.lineBreakMode = .byWordWrapping
if #available(iOS 14.0, *) {
// Disable the new line break strategy used by UIKit that moves at least two words
// to the next line which makes the title look odd.
// See: https://stackoverflow.com/q/46200027/351305
titleLabel.lineBreakStrategy = []
}
return titleLabel
}()
let bodyLabel: UILabel = {
let bodyLabel = UILabel()
bodyLabel.translatesAutoresizingMaskIntoConstraints = false
bodyLabel.font = UIFont.systemFont(ofSize: 18)
bodyLabel.textColor = .white
bodyLabel.numberOfLines = 0
bodyLabel.text = NSLocalizedString("PRIVACY_NOTICE_BODY", tableName: "Consent", comment: "Body.")
return bodyLabel
}()
let privacyPolicyLink: LinkButton = {
let button = LinkButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.titleString = NSLocalizedString(
"PRIVACY_POLICY_LINK_TITLE",
tableName: "Consent",
comment: "Title for link to privacy policy web page."
)
button.setImage(UIImage(named: "IconExtlink"), for: .normal)
return button
}()
let agreeButton: AppButton = {
let button = AppButton(style: .default)
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "AgreeButton"
button.setTitle(NSLocalizedString(
"CONTINUE_BUTTON_TITLE",
tableName: "Consent",
comment: "Title for button used for agreeing with privacy notice."
), for: .normal)
return button
}()
let scrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
return scrollView
}()
let scrollContentContainer: UIView = {
let contentView = UIView()
contentView.translatesAutoresizingMaskIntoConstraints = false
contentView.layoutMargins = UIMetrics.contentLayoutMargins
return contentView
}()
let footerContainer: UIView = {
let container = UIView()
container.translatesAutoresizingMaskIntoConstraints = false
container.layoutMargins = UIMetrics.contentLayoutMargins
container.backgroundColor = .secondaryColor
return container
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubviews()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Private
private func addSubviews() {
addSubview(scrollView)
addSubview(footerContainer)
scrollView.addSubview(scrollContentContainer)
[titleLabel, bodyLabel, privacyPolicyLink].forEach { scrollContentContainer.addSubview($0) }
footerContainer.addSubview(agreeButton)
scrollView.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
footerContainer.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
scrollView.leadingAnchor.constraint(equalTo: leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: trailingAnchor),
scrollContentContainer.widthAnchor.constraint(equalTo: scrollView.widthAnchor),
scrollContentContainer.topAnchor.constraint(equalTo: scrollView.topAnchor),
scrollContentContainer.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
scrollContentContainer.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
scrollContentContainer.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
footerContainer.topAnchor.constraint(equalTo: scrollView.bottomAnchor),
footerContainer.leadingAnchor.constraint(equalTo: leadingAnchor),
footerContainer.trailingAnchor.constraint(equalTo: trailingAnchor),
footerContainer.bottomAnchor.constraint(equalTo: bottomAnchor),
agreeButton.topAnchor.constraint(equalTo: footerContainer.layoutMarginsGuide.topAnchor),
agreeButton.leadingAnchor.constraint(equalTo: footerContainer.layoutMarginsGuide.leadingAnchor),
agreeButton.trailingAnchor.constraint(equalTo: footerContainer.layoutMarginsGuide.trailingAnchor),
agreeButton.bottomAnchor.constraint(equalTo: footerContainer.layoutMarginsGuide.bottomAnchor),
titleLabel.topAnchor.constraint(equalTo: scrollContentContainer.layoutMarginsGuide.topAnchor),
titleLabel.leadingAnchor.constraint(equalTo: scrollContentContainer.layoutMarginsGuide.leadingAnchor),
titleLabel.trailingAnchor.constraint(equalTo: scrollContentContainer.layoutMarginsGuide.trailingAnchor),
bodyLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 24),
bodyLabel.leadingAnchor.constraint(equalTo: scrollContentContainer.layoutMarginsGuide.leadingAnchor),
bodyLabel.trailingAnchor.constraint(equalTo: scrollContentContainer.layoutMarginsGuide.trailingAnchor),
privacyPolicyLink.topAnchor.constraint(equalTo: bodyLabel.bottomAnchor, constant: 24),
privacyPolicyLink.leadingAnchor.constraint(equalTo: scrollContentContainer.layoutMarginsGuide.leadingAnchor),
privacyPolicyLink.trailingAnchor.constraint(lessThanOrEqualTo: scrollContentContainer.layoutMarginsGuide.trailingAnchor),
privacyPolicyLink.bottomAnchor.constraint(equalTo: scrollContentContainer.layoutMarginsGuide.bottomAnchor),
])
}
}
|