根据某些用户输入的结果,我必须显示0到n个图像[图表样式背景中的行] 视图,在x轴上改变,
问题是我手头不知道需要绘制多少图像,
所以我无法创建所需的所有UIImageViews [也不是优雅的编码]
这里是我的意思的一个例子
UIImageView *img = [[[UIImageView alloc] initWithFrame:CGRectMake(12, 30, 12, 200)] autorelease];
[img setImage:[UIImage imageNamed:@"line.png"]];
img.opaque = YES;
[self.view addSubview:img];
//[img release];
UIImageView *img2 = [[[UIImageView alloc] initWithFrame:CGRectMake(102, 30, 12, 200)] autorelease];
[img2 setImage:[UIImage imageNamed:@"line.png"]];
img2.opaque = YES;
[self.view addSubview:img2];
UIImageView *img3 = [[[UIImageView alloc] initWithFrame:CGRectMake(202, 30, 12, 200)] autorelease];
[img3 setImage:[UIImage imageNamed:@"line.png"]];
img3.opaque = YES;
[self.view addSubview:img3];
UIImageView *img4 = [[[UIImageView alloc] initWithFrame:CGRectMake(302, 30, 12, 200)] autorelease];
[img4 setImage:[UIImage imageNamed:@"line.png"]];
img4.opaque = YES;
[self.view addSubview:img4];
那怎么做呢?
非常感谢!
答案 0 :(得分:0)
如果在height
中您的视图高度,则:
for (int x=2; x<height; x+=100)
{
UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(x, 30, 12, 200)];
[img setImage:[UIImage imageNamed:@"line.png"]];
img.opaque = YES;
[self.view addSubview:img];
[img release];
}