文字添加图片

2019-06-18  本文已影响0人  Skysama
NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:@"你好呀"];
        
        /**
         添加图片到指定的位置
         */
        NSTextAttachment *attchImage = [[NSTextAttachment alloc] init];
        // 表情图片
        attchImage.image = [UIImage imageNamed:@"icon"];
        // 设置图片大小
        attchImage.bounds = CGRectMake(2, 0, 12, 12);
        NSAttributedString *stringImage = [NSAttributedString attributedStringWithAttachment:attchImage];
        [attriStr insertAttributedString:stringImage atIndex:4];
        
        cell.textLabel.attributedText = attriStr;
上一篇 下一篇

猜你喜欢

热点阅读