iOS 在textView中添加图片

时间:2025-02-13 07:00:37
        CMSListCell *cell = (CMSListCell *)[ viewWithTag:];
        // textview add image
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:];
        NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil] ;
         = editedImage; //要添加的图片
        NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
        [string insertAttributedString:textAttachmentString atIndex:0];//index为用户指定要插入图片的位置
         = string;