Combining text and images in `UITextView`

前端 未结 3 1084
醉酒成梦
醉酒成梦 2020-12-09 00:15

Before I begin, let me acknowledge that similar questions exist, some with answers, others without. However, they do not address my specific problem. If you know of any, ple

3条回答
  •  隐瞒了意图╮
    2020-12-09 00:52

    __block  NSTextAttachment *imageAttachment = [NSTextAttachment new];
            imageAttachment.bounds = CGRectMake(0, -5, 20, 20);
            NSAttributedString *stringWithImage = [NSAttributedString attributedStringWithAttachment:imageAttachment];
            [deCodedString replaceCharactersInRange:NSMakeRange(deCodedString.length, 0) withAttributedString:stringWithImage];
            incomingMessage.messageAttributedString = deCodedString;
    
        SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
        imageAttachment.image = [UIImage imageNamed:@"profile_main_placeholder"];
    
        [downloader downloadImageWithURL:aURL
                                 options:0
                                progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                                    // progression tracking code
                                }
                               completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
                                   if (image && finished) {
                                       [image drawInRect:CGRectMake(0, 0, 20, 20)];
                                       imageAttachment.image = image;
    
                                       dispatch_async(dispatch_get_main_queue(), ^(void)
                                                      {
    
                                                          [self.tbl_Conversation reloadRowsAtIndexPaths:[self.tbl_Conversation indexPathsForVisibleRows]
                                                                                       withRowAnimation:UITableViewRowAnimationNone];
                                                          [self.tbl_Conversation reloadData];
                                                      });
    
    
    
                                       //                                                              NSAttributedString *stringWithImage = [NSAttributedString attributedStringWithAttachment:imageAttachment];
                                       //                                                              [deCodedString replaceCharactersInRange:NSMakeRange(deCodedString.length, 0) withAttributedString:stringWithImage];
                                       //                                                              incomingMessage.messageAttributedString = deCodedString;
                                   }
                               }];
    

提交回复
热议问题