let ruleAstr = NSMutableAttributedString.init(string: "登录及代表阅读并同意服务条款")
let pstyle = NSMutableParagraphStyle()
pstyle.alignment = NSTextAlignment.center
ruleAstr.addAttributes([NSAttributedString.Key.paragraphStyle : pstyle], range: NSRange(location: 0, length: ruleAstr.length))
ruleAstr.addAttributes([NSAttributedString.Key.foregroundColor : UIColor.lightGray], range: NSRange(location: 0, length: ruleAstr.length))
ruleAstr.addAttributes([NSAttributedString.Key.font : FONT12], range: NSRange(location: 0, length: ruleAstr.length))
ruleAstr.addAttributes([NSAttributedString.Key.foregroundColor : kMainBlueColor], range: ruleAstr.mutableString.range(of: "服务条款"))
ruleAstr.addAttribute(NSAttributedString.Key.link, value: URL(string: "ruleAct")!, range: ruleAstr.mutableString.range(of: "服务条款"))
ruleT.attributedText = ruleAstr
ruleT.isEditable = false
ruleT.delegate = self
extension LoginVC: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
if URL.absoluteString == "ruleAct" {
JJLog("点击条款")
}
return false
}
}
网友评论