0

次のような画像の URLNSArrayを含む があります。NSString

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ですか?

次のように1つの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 に答える