0

我有一个NSArray包含NSStrings 的图像网址,如下所示:

NSArray *array = [NSArray arrayWithObjects:@"http://graphics8.nytimes.com/images/2014/07/22/blogs/20140722-lens-mark-slide-SG5C/20140722-lens-mark-slide-SG5C-custom1.jpg", @"http://graphics8.nytimes.com/images/2014/07/22/blogs/20140722-lens-mark-slide-SG5C/20140722-lens-mark-slide-SG5C-custom2.jpg", @"http://graphics8.nytimes.com/images/2014/07/22/blogs/20140722-lens-mark-slide-6N62/20140722-lens-mark-slide-6N62-blog480.jpg", nil];

我如何得到CGSize每个imageUrl

我知道如何获得一个 imageUrl 的大小,如下所示:

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://graphics8.nytimes.com/images/2014/07/22/blogs/20140722-lens-mark-slide-SG5C/20140722-lens-mark-slide-SG5C-jumbo.jpg"]]];
CGSize imageSize = image.size;
4

1 回答 1

2
for(NSString *stringURL in array)
{
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:stringURL]]];
    CGSize imageSize = image.size;
}

我不建议在主线程中这样做。

如果要获取大小数组,则应执行以下操作:

NSMutableArray *sizes = [NSMutableArray array];
for(NSString *stringURL in array)
{
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:stringURL]]];
    CGSize imageSize = image.size;
    [sizes addObject:[NSValue valueWithCGSize:imageSize];
}

之后,您可以通过CGSize以下方式获得:

CGSize imageSize = [sizes[index] CGSizeValue];
于 2014-07-23T12:12:45.513 回答