I’m adding n UILable to n UIView organized by 2 columns but just the first UILabel shows up.
here is my code:
for(int i=0; i<ieneN; i++){
UIView *ienaSx = [[UIView alloc] init];
UIView *ienaDx = [[UIView alloc] init];
ienaSx.frame = CGRectMake(0.0, i*95.0, 160.0, 95.0);
if(i%2==0)
ienaSx.backgroundColor = [UIColor redColor];
else
ienaSx.backgroundColor = [UIColor greenColor];
UILabel *ienaSxLabel = [[UILabel alloc] init];
ienaSxLabel.frame = CGRectMake(0.0, (i*95.0)+80.0, 160.0, 15.0);
ienaSxLabel.text = [NSString stringWithFormat:@"Iena n°: %i", i];
[ienaSx addSubview:ienaSxLabel];
[scrollView addSubview:ienaSx];
ienaDx.frame = CGRectMake(160.0, i*95.0, 160.0, 95.0);
if(i%2==0)
ienaDx.backgroundColor = [UIColor greenColor];
else
ienaDx.backgroundColor = [UIColor redColor];
UILabel *ienaDxLabel = [[UILabel alloc] init];
ienaDxLabel.frame = CGRectMake(160.0, (i*95.0)+80.0, 160.0, 15.0);
ienaDxLabel.text = [NSString stringWithFormat:@"Iena n°: %i", i+1];
[ienaDx addSubview:ienaDxLabel];
[scrollView addSubview:ienaDx];
}
see this picture for a clearer explanation: http://imageshack.us/photo/my-images/269/schermata20110716a18064.png/
is there someone that can tell me where i’m wrong?
Thank You very much!
Try this for setting the label’s frame:
The same for
Also don’t forget to release your objects (views and labels) after you add them to the superview.