Ful*_*uli 9 nsattributedstring nstextattachment
我已经花了3个小时,但是无法解决它,有人知道为什么吗?请帮我!
下面的代码添加了一个图像作为属性字符串的附件,
UIImage *img = [UIImage imageNamed:imgName];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = img;
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] init];
[attrStr appendAttributedString:attrStringWithImage];
Run Code Online (Sandbox Code Playgroud)
然后我将attrStr分配给UITextView的attributionText,这在iOS 7中运行良好但在iOS 6中没有显示图像,我听说自iOS 6以来UITextView支持的属性文本,我应该为iOS 6做什么不同?
PS:在iOS 6中,如果我将attrStr分配给UILabel的attributedText,它会显示,UITextView的特殊之处是什么?
小智 1
+ (NSAttributedString *)attributedStringWithAttachment:(NSTextAttachment *)attachment适用于 iOS 7.0 及更高版本。因此,在 iOS 6 及更早版本的 iOS 中,您可以使用 UIWebView 或第三方库在 Label 或 TextView 中显示图像。
| 归档时间: |
|
| 查看次数: |
9924 次 |
| 最近记录: |