how to place different UIImages
Depending on the result of some user input, i have to show from 0 to n number of images [lines in a chart style background] in a view, changing on the x axis,
the problem is that i dont know before hand how many images are going to be needed to draw,
so i cannot create all the UIImageViews needed [nor is elegant coding]
here an example of what I mean
UIImageView *img = [[[UIImageV开发者_C百科iew 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];
so how to accomplish this?
thanks a lot!
If in height
you have height of your view, than:
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];
}
精彩评论