【发布时间】:2017-06-21 11:11:42
【问题描述】:
我正在开发一个在 Imageview 上显示多个图像的视图,并且图像的数量是动态的。 我通过 URL 获取这些图像,并且 URL 的字符串存储在一个数组中。
我采用了一个 for 循环来为要在其上显示的每个图像创建一个新的图像视图。 imageview 的 frame 是根据图像的大小来设置的。但问题是,当图像数量超过 5 个时,第 6 个图像就会出现在屏幕之外。但是如果数组中有超过 5 个图像,我希望它向下移动。
下面是我使用 for-loop 在 imageview 上显示图像的代码
int x=0;
for (int i=0;i<[items count]; i++)
{
NSLog(@"image name %@",[items objectAtIndex:i]);
NSLog(@"image url %@",[NSURL URLWithString:[NSString stringWithFormat:@"%@",[items objectAtIndex:i]]]);
NSString* urlTextEscaped = [[NSString stringWithFormat:@"%@",[items objectAtIndex:i]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *imgData=[NSData dataWithContentsOfURL:[NSURL URLWithString:urlTextEscaped]];
UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageWithData:imgData]];
imgV.frame=CGRectMake(x, 0, 50, 50);
[cell.contentView addSubview:imgV];
x=x+imgV.frame.size.width+10;
}
【问题讨论】:
-
为什么不使用表格视图或滚动视图??
标签: ios objective-c image for-loop uiimageview