2

我有以下代码在 UIImageView 上加载我想要从互联网上获得的图像:

NSString* mapURL = @"http://mydomain.com/image-320x480.png";
NSData* imageData = [[NSData alloc]initWithContentsOfURL:url];

 UIImage* image = [[UIImage alloc] initWithData:imageData];
 [marcaBackground setImage:image];
 [imageData release];
 [image release];

我不想硬编码图像的 URL,而是加载另一个 URL 的字符串,然后将该图像加载到 UIImageView 上。

我的 URL 仅返回另一个文本格式的 URL。

例如:http://mydomain.com/url退货 http://mydomain.com/image-320x480.png

我怎么能完成这个任务?

4

1 回答 1

3

采用:

NSData *imageData = 
   [[NSData alloc] initWithContentsOfUrl:
       [NSString 
           stringWithContentsOfUrl: 
             [NSURL URLWithString:@"http://mydomain.com"]
           encoding: NSUTF8StringEncoding
           error: nil
       ]
   ];

然后像你已经做的那样继续。

UIImage* image = [[UIImage alloc] initWithData:imageData];
[marcaBackground setImage:image];
[imageData release];
[image release];
于 2010-10-01T16:11:07.630 回答