我有一个 NSArray
,其中包含 NSString
图片 url,如下所示:
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];
如何获取每个 imageUrl
的 CGSize
?
我知道如何像这样获取一个 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;
最佳答案
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];
关于ios - 如何在 NSArray 中获取图像 url 的 CGSizes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24910162/