Vol*_*da2 0 iphone uiimageview uiimage
我看不到任何图片.为什么?
UIImage *photoImg = [UIImage imageNamed:@"http://blog.leadcritic.com/wp-content/uploads/2011/02/favorite_animal_picture.jpg"];
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:photoImg];
[self.view addSubview:imageView2];
Run Code Online (Sandbox Code Playgroud)
因为如果你使用代码:
[UIImage imageNamed:@"mypicture.png"];
Run Code Online (Sandbox Code Playgroud)
图像应该在iPhone上,而不是从URL加载.从URL您需要使用以下内容:
NSString path = @"http://blog.leadcritic.com/wp-content/uploads/2011/02/favorite_animal_picture.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *photoImg = [[UIImage alloc] initWithData:data cache:NO];
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:photoImg];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
153 次 |
| 最近记录: |