Dynamically creating subviews of similar type
Posted
by
Akki
on Stack Overflow
See other posts from Stack Overflow
or by Akki
Published on 2011-02-13T23:21:01Z
Indexed on
2011/02/13
23:25 UTC
Read the original article
Hit count: 213
My code for above view is:
-(void)viewWillAppear:(BOOL)animated{
float yh = 0;
while (yh<200) {
//UIView
CGRect myFrame = CGRectMake(0, yh, 320, 30);
UIView *myFirstView = [[UIView alloc] initWithFrame:myFrame];
myFirstView.backgroundColor = [UIColor orangeColor];
//IUILabel in UIView
CGRect mylblFrame = CGRectMake(5, yh, 60, 15);
UILabel *lblsize = [[UILabel alloc] initWithFrame:mylblFrame];
lblsize.text = @"Hello";
[myFirstView addSubview:lblsize];
CGRect mylbl_hi = CGRectMake(80, yh, 60, 15);
UILabel *lbl_hi = [[UILabel alloc] initWithFrame:mylbl_hi];
lbl_hi.text = @"Hii";
[myFirstView addSubview:lbl_hi];
[self.view addSubview:myFirstView];
[lbl_hi release];
[lblsize release];
[myFirstView release];
yh=yh+40;
}
[super viewWillAppear:YES];
}
I can't understand reason of it being like this...i wanted labels to be attached with my subviews of orange color...this may be odd day for me to understand what's wrong with my code...if any of you can tell me where i ma doing wrong would be great to me. This is my first time creating view programmatically..so please excuse me if all this is silly question
© Stack Overflow or respective owner