
代码如下:
```objc
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake (0, 20, self.view.frame.size.width, self.view.fame.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 就无法显示了 ---求助各路大神 1 CDuXZMAPgHp1q9ew 2015-09-17 17:10:36 +08:00 哥们你是新手吧 下载是异步的, 这时候 image 还没下好呢 |