介绍:点击打开链接
设置带特殊属性的文本:
NSRange highlightedRange = [text rangeOfString:NSLocalizedString(@"highlighted", nil)];// 获取设置的文本范围
[attributedText addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:underlinedRange];// 设置
设置带图片的文本:
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
UIImage *imageAttachment = [UIImage imageNamed:@"/Users/npu_wy/Desktop/image2/image9.png"];
textAttachment.image = imageAttachment;
textAttachment.bounds = CGRectMake(0, 0, imageAttachment.size.width, imageAttachment.size.height);
NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
[attributedText appendAttributedString:textAttachmentString];
设置:
textView.attributedText = attributedText;
attributedText-> textAttachmentString -> textAttachment -> imageAttachment