zoukankan      html  css  js  c++  java
  • NSAttributedString可以强制转换为NSMutableAttributedString类型吗?下面这代码有什么问题 为什么报错

     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; 有问题 但可以打印出来
     
  • 相关阅读:
    Oracle使用正则表达式拆分字段里多行分布式值
    Oracle--创建TRIGGER实现跟踪用户登录信息
    Oracle传输数据到Sqlserver
    Oracle---智斗ORA01427
    区别集合之间的不同
    maven
    集合与数组的区别
    调用系统命令实现删除文件的操作
    JAVA列出某文件夹下的所有文件
    JVM加载类的原理机制
  • 原文地址:https://www.cnblogs.com/seeworld/p/6648735.html
Copyright © 2011-2022 走看看