class MdyAgreeView: UIView,Nibloadable {
let textContent:String = "请仔细阅读《用户服务条款》和《用户隐私政策》我们将按照您同意的条款使用您的个人信息,以便为您提供服务,我们尽全力保护您的个人信息安全如您同意此政策,请点击“同意”并开始使用我们的产品和服务。"
let text1:String = "《用户服务条款》"
let text2:String = "《用户隐私政策》"
@IBOutlet weak var agreeLab: YYLabel!
@IBOutlet weak var agreeLabH: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
}
override func layoutSubviews() {
super.layoutSubviews()
protocolIsSelect()
}
func protocolIsSelect() {
agreeLabH.constant = textContent.getBoundingFontHeight(rectWidth:agreeLab.frame.width,font: gsfont(18),lineSpacing: 8)
agreeLab.textAlignment = .left
agreeLab.numberOfLines = 0
agreeLab.textColor = colorFromHEX(colorVaule: "#616161")
let text = NSMutableAttributedString(string:textContent )
/// 3.设置高亮
if let range1 = textContent.range(of: text1) {
let nsRange = NSRange(range1, in: textContent)
text.yy_setTextHighlight(nsRange, color: UIColor.gsSelectColor, backgroundColor: .clear) { view, str, ran, frame in
/// "用户协议"
let webvc = GSSearviceWebVC()
webvc.url = User_Registration_Agreement
webvc.titleStr = "服务条款"
webvc.modalPresentationStyle = .fullScreen
getCurrentVC().present(webvc, animated: true)
}
}
if let range2 = textContent.range(of: text2) {
let nsRange = NSRange(range2, in: textContent)
text.yy_setTextHighlight(nsRange, color: UIColor.gsSelectColor, backgroundColor: .clear) { view, str, ran, frame in
let webvc = GSSearviceWebVC()
webvc.url = User_Privacy_Agreement
webvc.titleStr = "服务隐私政策"
webvc.modalPresentationStyle = .fullScreen
getCurrentVC().present(webvc, animated: true)
}
}
text.yy_lineSpacing = 8
text.yy_font = gsfont(18)
agreeLab.attributedText = text
// 居中显示一定要放在这里,放在viewDidLoad不起作用
}
@IBAction func agree(_ sender: Any) {
userDefault.set("12", forKey: "isAgree")
self.removeFromSuperview()
}
@IBAction func notagree(_ sender: Any) {
exit(0)
}
}
Swift YYLabel 高亮 点击事件
最新推荐文章于 2024-06-15 09:52:23 发布