2011-05-17 33 views
0

我看不到任何图片。为什么?我看不到任何图片。为什么?

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]; 

回答

7

因为如果你使用的代码:

的形象应该是在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]; 
0

您没有设置imageView2

imageView2.frame = CGRectMake(0, 0, 100, 100); // Or whatever. 
框架
相关问题