因为公司项目上,需要某一行作为URL,并且可以跳转Safari。哈哈,然后就使用了textView。
注意注意: 想要让textView能跳转Safari,一定!!!! 一定要在前面加http或者https
//event_fs18_description_website = www.baidu.com
//用来作为显示的文字
NSMutableAttributedString *websiteAttriStr = [[NSMutableAttributedString alloc] initWithString:PGLocalizedString(@"event_fs18_description_website")];
//你跳转需要的link
[websiteAttriStr addAttribute:NSLinkAttributeName value:[NSString stringWithFormat:@"https://%@",websiteAttriStr.string] range:NSMakeRange(0, websiteAttriStr.length)];
以上两句代码就是为了显示和跳转内容不同
[websiteAttriStr addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(0, websiteAttriStr.length)];
[websiteAttriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17.0] range:NSMakeRange(0, websiteAttriStr.length)];
self.descriptionTextView.attributedText = websiteAttriStr;
self.descriptionTextView.translatesAutoresizingMaskIntoConstraints = YES;
[self.descriptionTextView sizeToFit];