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

NSAttributedString可以强制转换为NSMutableAttributedString类型吗?下面这代码有什么问题 为什么报错

时间:2017-03-30 23:09:38      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:integer   pre   span   images   http   属性   named   mode   ini   

 1 -(void)insetEmotion:(EmotionModel*)emotionModel{
 2     if(emotionModel.code){
 3         /**
 4          在TextView中插入图片首选要知道光标的位置 比如在一段文字中间 或着 一段文字末尾
 5          
 6          */
 7         //self.statusTextView.text = emotionModel.chs;
 8         /**
 9          这个方法会自动将传入的参数插入到光标的位置
10          现在插入的是对应的文字信息 以后会把这个信息发送给新浪
11          现在要将文字信息以图片显示在文本框中
12          emoji就是字符串 这样可以直接插入到 文本框中
13          */
14         [self insertText:emotionModel.code.emoji];
15         
16     }else if(emotionModel.png){
17         
18         UIImage *image = [UIImage imageNamed:emotionModel.png];
19         
20         NSTextAttachment *attch = [[NSTextAttachment alloc]init];
21         attch.image = image;
22         CGFloat WHImage = self.font.lineHeight;
23         attch.bounds = CGRectMake(0, -4, WHImage, WHImage);
24         /** 将一个附件转化为一个字符串*/
25         NSAttributedString *imageStr = [NSAttributedString attributedStringWithAttachment:attch];
26         //插入属性文字到光标
27         [self insertAttributeText:imageStr];
28         NSMutableAttributedString *mutableAttr =(NSMutableAttributedString *)self.attributedText;
29         NSLog(@"%@",mutableAttr);
30         //NSInteger count = mutableAttr.length;
31         //NSRange range = NSMakeRange(0, count);
32         //NSLog(@"%@",NSRangeFromString(range));
33         [mutableAttr addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(0, mutableAttr.length)];
34         
35           }
36  
37 }

感觉

NSMutableAttributedString *mutableAttr =(NSMutableAttributedString *)self.attributedText; 有问题 但可以打印出来
技术分享

 

 

NSAttributedString可以强制转换为NSMutableAttributedString类型吗?下面这代码有什么问题 为什么报错

标签:integer   pre   span   images   http   属性   named   mode   ini   

原文地址:http://www.cnblogs.com/seeworld/p/6648735.html

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