我正在用 Objective-C 开发,我想在 AlertView
中通过 http url
显示图像?
我已经得到像这样的图片 url:http://192.72.1.1/DCIM/100__DSC/SNAP0053.JPG
,并转换 NSURL
到 NSString
。但是我无法在 AlertView 中显示图像,它是空的。
将url转成NSString显示在AlertView中的代码如下:
NSString *path = [url absoluteString];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: path]];
UIImage *Image=[UIImage imageWithData:imageData];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Image" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImage:Image];
[alert addSubview:imageView];
[alert show];
但是AlertView并没有像下图那样显示任何图像。
我是不是漏掉了什么?
如何在 Objective-C 的 AlertView 中通过 http url 显示图像?
最佳答案
您不能在 AlertView 中添加图像。 在 iOS 7 之前是可能的。 您可以创建自定义 AlertView 并向其添加图像。
也看看这个
关于ios - 如何在 Objective-C 的 AlertView 中通过 http url 显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28426868/