• 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; 有问题 但可以打印出来
     
  • 相关阅读:
    latex
    slab着色,可以减少cache conflict miss概率么?
    内存管理 初始化(八) 至kswapd_init
    内存管理 初始化(七)kmem_cache_init_late 初始化slab分配器(下)
    vmwareubuntu18.04网络配置
    高德地图的一些使用心得
    mongodb聚合管道用法
    python学习链接
    python开发者常犯的10个错误(转)
    vim配置python开发环境(转)
  • 原文地址:https://www.cnblogs.com/seeworld/p/6648735.html
Copyright © 2020-2023  润新知