null - iOS Bounds of UIView in ViewDidLoad -


i wanted use bounds of uiview create uilabel , add uiview inside viewdidload method, however, have found bounds of uiview still null inside viewdidload. when @ demo app, bounds of uiview initialised in viewdidload.

in interface have

@interface viewcontroller : uiviewcontroller @property (weak, nonatomic) iboutlet uiview *promotionview; @end 

and trying do

- (void)viewdidload {     [super viewdidload];     uiview *container = [[uiview alloc] initwithframe:self.promotionview.bounds];      uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(10, container.bounds.size.height-100, 320, 20)];     label.text = @"promotion title";     [container addsubview:label];     [self.promotionview addsubview: container]; } 

but doesn't work because bounds of promotionview null.

you can in viewdidappear:

-(void)viewdidappear:(bool)animated {     static int first = 1;     if (first) {         uiview *container = [[uiview alloc] initwithframe:self.promotionview.bounds];          uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(10, container.bounds.size.height-100, 320, 20)];         label.text = @"promotion title";         [container addsubview:label];         [self.promotionview addsubview: container];         first = 0;     }  } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -