我有一个NSArray
,其中包含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
的{{1}}?
我知道如何获得一个imageUrl的大小:
imageUrl
答案 0 :(得分: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];