美文网首页
Swift Range转NSRange

Swift Range转NSRange

作者: 汴城码农 | 来源:发表于2019-11-26 17:18 被阅读0次
        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;

相关文章

网友评论

      本文标题:Swift Range转NSRange

      本文链接:https://www.haomeiwen.com/subject/xxdywctx.html