V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
lufir
V2EX  ›  iOS

求助: ios 如何用 NSTextattAchment 加载 SDWebImage 下载下来的图片

  •  
  •   lufir · Sep 17, 2015 · 2557 views
    This topic created in 3881 days ago, the information mentioned may be changed or developed.

    代码如下:
    ```objc

    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake (0, 20, self.view.frame.size.width, self.view.frame.size.height-20 )];
    [self.view addSubview:textView];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    [imageView sd_setImageWithURL:[NSURL URLWithString:@"http://7bv920.com1.z0.glb.clouddn.com/20150901.jpg"]];
    
    NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    attachment.image = imageView.image;
    attachment.bounds = CGRectMake (0, 20, self.view.frame.size.width, 300 );
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithAttributedString:textView.attributedText];
    NSAttributedString *imageStr = [NSAttributedString attributedStringWithAttachment:attachment];
    [attStr appendAttributedString:imageStr];
    textView.attributedText = attStr;
    
    1.图片加载是正确的,如果直接将 imageview 显示在 self.view 上可以显示。
    2.用 NSTextAttachment 直接加载一张本地图片也可以正常显示
    3.用 NSTextattAchment 加载 imageview.image 就无法显示了
    
    ---求助各路大神
    
    CDuXZMAPgHp1q9ew
        1
    CDuXZMAPgHp1q9ew  
       Sep 17, 2015   ❤️ 1
    哥们你是新手吧 下载是异步的, 这时候 image 还没下好呢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2527 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 02:36 · PVG 10:36 · LAX 19:36 · JFK 22:36
    ♥ Do have faith in what you're doing.