let attrString : NSMutableAttributedString = NSMutableAttributedString(string: "登录注册代表你已同意用户协议")
attrString.yy_setFont(UIFont.systemFont(ofSize: 16), range: attrString.yy_rangeOfAll())
let range:Range = attrString.string.range(of: "用户协议")!
let location:Int = attrString.string.distance(from: attrString.string.startIndex, to: range.lowerBound)
let length:Int = attrString.string.distance(from: range.lowerBound, to: range.upperBound);
let nsrange:NSRange = NSRange(location: location, length: length)
attrString.yy_alignment = NSTextAlignment.center
attrString.yy_setTextHighlight(nsrange, color: UIColor.blue, backgroundColor: UIColor.clear) { (view, attr, range, rect) in
let storyboard = UIStoryboard(name: "UserLoginProfile", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "agreement_vc")
self.navigationController?.pushViewController(vc, animated: true)
}
yylabel.attributedText = attrString;
网友评论