iOS 在textView中添加圖片

        CMSListCell *cell = (CMSListCell *)[self.view viewWithTag:self.tag];
        // textview add image
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:cell.listTextView.attributedText];
        NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil] ;
        textAttachment.image = editedImage; //要添加的圖片
        NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
        [string insertAttributedString:textAttachmentString atIndex:0];//index爲用戶指定要插入圖片的位置
        cell.listTextView.attributedText = string;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章