Я не вижу ни одной картинки.Зачем? - PullRequest
0 голосов
/ 17 мая 2011

Я не вижу ни одной картинки. Почему?

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

Ответы [ 2 ]

7 голосов
/ 17 мая 2011

Потому что, если вы используете код:

[UIImage imageNamed:@"mypicture.png"];

Изображение должно быть на 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 голосов
/ 17 мая 2011

Вы не установили кадр imageView2

imageView2.frame = CGRectMake( 0, 0, 100, 100 ); // Or whatever.
...