ios - Programatically generated UILabel origin point incorrectly to (0.0) set on first load -


i trying programatically generate 2 uilabels in application each uiimageview on storyboard. code runs , works correctly, however, on first load 2 uilabels form in (0.0) coordinate of main view, opposed uiimageview frame origin.x,origin.y. can't understand why happening.

if click on different tab , return page, labels generate in correct location.

why this? how can generate labels in correct location?

-(void) viewwillappear:(bool)animated {     //removed unneccessary code above...     int = 0;     (uiimageview *plantscreen in self.view.subviews)     {         if ([plantscreen ismemberofclass:[plant class]])         {             @try             {                 //the label hold name                 uilabel *plantname = [[uilabel alloc] initwithframe:cgrectmake((plantscreen.frame.origin.x), (plantscreen.frame.origin.y+ plantscreen.frame.size.height), 160, 30.0)];                 plantname.numberoflines = 1;                 plantname.minimumscalefactor = .5;                 plantname.adjustsfontsizetofitwidth = yes;                 [plantname settextalignment:nstextalignmentcenter];                 [plantname setbackgroundcolor:[uicolor clearcolor]];                  [self.view addsubview:plantname];                 plantname.hidden = false;                  [self.view bringsubviewtofront:plantname];                  //create label hold quantity                 uilabel *quantity = [[uilabel alloc] initwithframe:cgrectmake((plantscreen.frame.origin.x), (plantscreen.frame.origin.y+ plantscreen.frame.size.height + 20), 160, 30.0)];                  [quantity settextalignment:nstextalignmentcenter];                 [quantity setbackgroundcolor:[uicolor clearcolor]];                 quantity.text = [nsstring stringwithformat:@"%d",plant.quantity];                 [self.view addsubview:quantity];                 quantity.hidden = false;                 [self.view bringsubviewtofront:quantity];                  i++;                 }             @catch (nsexception *exception)             {                    nslog(@"an exception occured: %@", [exception reason]);             }             @finally             {              }         }     } } 

frame of uiimageview depends on image being drawn , contentmode property. can try setting contentmode uiviewcontentmodescaleaspectfill see if forces keep assigned frame.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -