码迷,mamicode.com
首页 > 其他好文 > 详细

在UITextview中添加链接属性的文字

时间:2016-01-20 19:22:58      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

    let termsAndPrivacyLabel = UITextView(frame: CGRect(x: 24/2, y: 0, width: width, height: height))
        let string = "By signing up, you agree to the Terms of Use & Privacy Policy."
        let text = NSMutableAttributedString(string: string, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(11.6)])
        text.addAttribute(NSLinkAttributeName, value: "https://github.com/site/terms", range: NSMakeRange(32, 12))
        text.addAttribute(NSLinkAttributeName, value: "https://github.com/site/privacy", range: NSMakeRange(47, 14))
        termsAndPrivacyLabel.attributedText = text
        termsAndPrivacyLabel.autoresizingMask = .FlexibleWidth
        termsAndPrivacyLabel.backgroundColor = UIColor.clearColor()
        termsAndPrivacyLabel.contentInset.top = 3 // shows the top dot of text-selector bar
        termsAndPrivacyLabel.editable = false
        termsAndPrivacyLabel.scrollEnabled = false
        tableFooterView.addSubview(termsAndPrivacyLabel)

 点击该高亮的文字会自动跳转到链接界面

 

在UITextview中添加链接属性的文字

标签:

原文地址:http://www.cnblogs.com/mogul/p/5146171.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!