Make legal label tappable

This commit is contained in:
Niels Andriesse 2019-12-09 10:27:01 +11:00
parent 02a8a8a51a
commit 0c6c07cbfd

View file

@ -21,6 +21,21 @@ final class PublicKeyVC : UIViewController {
return result return result
}() }()
private lazy var legalLabel: UILabel = {
let result = UILabel()
result.textColor = Colors.text
result.font = .systemFont(ofSize: Values.verySmallFontSize)
let text = "By using this service, you agree to our Terms and Conditions and Privacy Statement"
let attributedText = NSMutableAttributedString(string: text)
attributedText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize), range: (text as NSString).range(of: "Terms and Conditions"))
attributedText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize), range: (text as NSString).range(of: "Privacy Statement"))
result.attributedText = attributedText
result.numberOfLines = 0
result.textAlignment = .center
result.lineBreakMode = .byWordWrapping
return result
}()
// MARK: Settings // MARK: Settings
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
@ -85,18 +100,17 @@ final class PublicKeyVC : UIViewController {
buttonStackViewContainer.pin(.trailing, to: .trailing, of: buttonStackView, withInset: Values.massiveSpacing) buttonStackViewContainer.pin(.trailing, to: .trailing, of: buttonStackView, withInset: Values.massiveSpacing)
buttonStackViewContainer.pin(.bottom, to: .bottom, of: buttonStackView) buttonStackViewContainer.pin(.bottom, to: .bottom, of: buttonStackView)
// Set up legal label // Set up legal label
let legalLabel = UILabel() legalLabel.isUserInteractionEnabled = true
legalLabel.set(.height, to: Values.onboardingButtonBottomOffset) let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleLegalLabelTapped))
legalLabel.textColor = Colors.text legalLabel.addGestureRecognizer(tapGestureRecognizer)
legalLabel.font = .systemFont(ofSize: Values.verySmallFontSize) // Set up legal label container
let legalLabelText = "By using this service, you agree to our Terms and Conditions and Privacy Statement" let legalLabelContainer = UIView()
let attributedLegalLabelText = NSMutableAttributedString(string: legalLabelText) legalLabelContainer.set(.height, to: Values.onboardingButtonBottomOffset)
attributedLegalLabelText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize), range: (legalLabelText as NSString).range(of: "Terms and Conditions")) legalLabelContainer.addSubview(legalLabel)
attributedLegalLabelText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize), range: (legalLabelText as NSString).range(of: "Privacy Statement")) legalLabel.pin(.leading, to: .leading, of: legalLabelContainer, withInset: Values.massiveSpacing)
legalLabel.attributedText = attributedLegalLabelText legalLabel.pin(.top, to: .top, of: legalLabelContainer)
legalLabel.numberOfLines = 0 legalLabelContainer.pin(.trailing, to: .trailing, of: legalLabel, withInset: Values.massiveSpacing)
legalLabel.textAlignment = .center legalLabelContainer.pin(.bottom, to: .bottom, of: legalLabel, withInset: 10)
legalLabel.lineBreakMode = .byWordWrapping
// Set up top stack view // Set up top stack view
let topStackView = UIStackView(arrangedSubviews: [ titleLabel, explanationLabel, publicKeyLabelContainer ]) let topStackView = UIStackView(arrangedSubviews: [ titleLabel, explanationLabel, publicKeyLabelContainer ])
topStackView.axis = .vertical topStackView.axis = .vertical
@ -110,7 +124,7 @@ final class PublicKeyVC : UIViewController {
topStackViewContainer.pin(.trailing, to: .trailing, of: topStackView, withInset: Values.veryLargeSpacing) topStackViewContainer.pin(.trailing, to: .trailing, of: topStackView, withInset: Values.veryLargeSpacing)
topStackViewContainer.pin(.bottom, to: .bottom, of: topStackView) topStackViewContainer.pin(.bottom, to: .bottom, of: topStackView)
// Set up main stack view // Set up main stack view
let mainStackView = UIStackView(arrangedSubviews: [ topSpacer, topStackViewContainer, bottomSpacer, buttonStackViewContainer, legalLabel ]) let mainStackView = UIStackView(arrangedSubviews: [ topSpacer, topStackViewContainer, bottomSpacer, buttonStackViewContainer, legalLabelContainer ])
mainStackView.axis = .vertical mainStackView.axis = .vertical
mainStackView.alignment = .fill mainStackView.alignment = .fill
view.addSubview(mainStackView) view.addSubview(mainStackView)
@ -164,4 +178,9 @@ final class PublicKeyVC : UIViewController {
}, completion: nil) }, completion: nil)
Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(enableCopyButton), userInfo: nil, repeats: false) Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(enableCopyButton), userInfo: nil, repeats: false)
} }
@objc private func handleLegalLabelTapped(_ tapGestureRecognizer: UITapGestureRecognizer) {
let url = URL(string: "https://github.com/loki-project/loki-messenger-ios/blob/master/privacy-policy.md")!
UIApplication.shared.open(url)
}
} }