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; 有问题 但可以打印出来
     
  • 相关阅读:
    CSS3 -- 透明色(rgba)
    CSS3 -- 多背景(backgrounds)
    CSS3 -- 背景原点(background-origin)
    CSS3 -- 背景裁剪(background-clip)
    CSS3 -- 背景尺寸(background-size)
    CSS3 -- 图片边框(border-image)
    CSS3 -- 边框颜色(border-color)
    CSS3 -- 盒模型(box-sizing)
    CSS -- 字体单位(px、em、rem)
    课程总结
  • 原文地址:https://www.cnblogs.com/seeworld/p/6648735.html
Copyright © 2011-2022 走看看