如何使用各种URL填充UIImageView



我有一个包含图像URL的数组,我想用这些URL创建一个图像视图(现在使用循环)。

但我没有想到,如何用阵列中的URL进行图像视图希望有人会澄清一下

int x = 0;
for(int i = 0; i <imagearry.count; i ++){
NSDictionary *dict = [imagearry objectAtIndex:i];
NSLog(@"%@",[dict objectForKey:@"img_url"]);
NSString *filePath [NSHomeDirectory()stringByAppendingPathComponent:@"/Library/Caches"];
    stringarry = [[imagearry objectAtIndex:i] objectForKey:@"img_url"];
    int x = 0;
    imageView.image = [UIImage imageNamed:[stringarry objectAtIndex:0]];
    for(int i=0; i < [stringarry count]; i++)
    {
        UIImageView *img = [[UIImageView alloc] init];
        img.bounds = CGRectMake(10, 10, 50, 50);
        img.frame = CGRectMake(5+x, 0, 160, 110);
        NSLog(@"image: %@",[stringarry objectAtIndex:i]);

        img.image = [UIImage imageNamed:[stringarry objectAtIndex:i]];
        [stringarry insertObject:img atIndex:i];
         [scrollView addSubview:[stringarry objectAtIndex:i]];
        x += 170;

uiimageView没有从URL显示图像的属性。 您可能必须以NSDATA格式下载它,然后转换为 UIImage .INSTEAD查看AsyncimageView并存储实例 数组中的AsyncimageView。

检查此链接:asyncimageView

您必须使用imageWithData而不是imageNamed

NSURL * url = [NSURL fileURLWithPath:[filePath stringByAppendingPathComponent:[stringarry objectAtIndex:i]]];
[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];

最新更新