Swift隐私条款弹框及查看隐私条款
为什么要写这么简单的东西呢?因为以后每个APP启动这是⼀个必须功能,总结出来后⾯就不⽤每个应⽤都去重新写
效果图.png
实现代码
import UIKit
let kPrivacyState = "kPrivacyState"
class WTPrivacyDialogViewController: UIViewController {
private var checkBtn: UIButton!
var actionBlock: ((Int) -> ())?
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.75)
tupUI()
yua}
func tupUI() {
let contentView = UIView()
contentView.backgroundColor = .white
Radius = 8
contentView.layer.masksToBounds = true
view.addSubview(contentView)
let titleLb = UILabel()
< = "隐私条款提⽰"
titleLb.font = UIFont.boldSystemFont(ofSize: 18)
contentView.addSubview(titleLb)
let style = NSMutableParagraphStyle()
德福报名style.lineSpacing = 5
let aStr = NSMutableAttributedString(string: "为了更好的保护您的权益,同时遵守相关督管要求,我们将通过《隐私政策》向您说明我们会如何搜集、存储、保护和使⽤您的 let subtitleLb = UILabel()
subtitleLb.numberOfLines = 0
subtitleLb.attributedText = aStr
contentView.addSubview(subtitleLb)
let button = UIButton(type:.custom)
button.tImage(UIImage(named: "checkbox-blank-circle-line"), for: .normal)
button.tImage(UIImage(named: "checkbox-circle-line"), for: .lected)
button.addTarget(lf, action:#lector(checkAction(_:)), for:.touchUpInside)
checkBtn = button
contentView.addSubview(checkBtn)
let agreeStr = NSMutableAttributedString(string: "已查看并同意《隐私政策》", attributes: [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 14), NSAttributedString. _tTextHighlight(NSRange(location: 6, length: 6), color: .blue, backgroundColor: .clear) { containerView, text, range, rect in
let vc = WTPrivacyContentViewController()
vc.title = "隐私政策"
let nav = UINavigationController(rootViewController: vc)
lf.prent(nav, animated: fal, completion: nil)
}
let agreeLb = YYLabel()莱切斯特大学
agreeLb.attributedText = agreeStr
contentView.addSubview(agreeLb)
let agreeBtn = UIButton(type: .custom)
agreeBtn.tTitle("同意", for: .normal)
英语单词翻译agreeBtn.tTitleColor(.white, for: .normal)游学团
agreeBtn.backgroundColor = .blue
Radius = 18
agreeBtn.layer.masksToBounds = true
agreeBtn.addTarget(lf, action:#lector(agreeAction(_:)), for:.touchUpInside)
contentView.addSubview(agreeBtn)
let regectBtn = UIButton(type: .custom)
m
appearslove explains it allregectBtn.addTarget(lf, action:#lector(regectAction(_:)), for:.touchUpInside)
regectBtn.tTitle("不同意并退出app", for: .normal)
永远爱你的英语怎么说regectBtn.tTitleColor(.blue, for: .normal)
contentView.addSubview(regectBtn)
contentView.snp_makeConstraints { make in
make.right.equalTo(-20)
make.left.equalTo(20)
make.bottom.equalTo(regectBtn.snp_bottom).offt(24)
}
情报学就业titleLb.snp_makeConstraints { make in
make.height.equalTo(26)
}
subtitleLb.snp_makeConstraints { make in
make.right.equalTo(-24)
make.left.equalTo(24)
aterThanOrEqualTo(60)
}
checkBtn.snp_makeConstraints { make in
make.left.equalTo(24)
make.size.equalTo(CGSize(width: 20, height: 20))
}
agreeLb.snp_makeConstraints { make in
make.height.equalTo(20)
make.left.equalTo(checkBtn.snp_right).offt(2)
}