UITextView学习记录

来源:互联网 发布:大学生网络诈骗感悟 编辑:程序博客网 时间:2024/05/17 23:22

介绍:点击打开链接


设置带特殊属性的文本:

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

0 0
原创粉丝点击