ios - Dynamic Button creation doesn't work -


can't figure out what's wrong - here's implementation of viewdidload() in uiviewcontroller; have 3 different ui elements dynamically created: uiimageview, uibutton , uilabel; though initiated in same way, turns out button not created correctly!

    - (void)viewdidload { [super viewdidload]; // additional setup after loading view.   self.mainimageview = [[uiimageview alloc] initwithframe:cgrectmake(0, self.navigationcontroller.navigationbar.frame.origin.y + self.navigationcontroller.navigationbar.frame.size.height, self.view.frame.size.width, self.view.frame.size.width)]; [self.view addsubview:self.mainimageview]; self.mainimageview.image = [uiimage imagenamed:@"main"];   self.buttontraining = [uibutton buttonwithtype:uibuttontypesystem]; [self.view insertsubview:self.buttontraining abovesubview:self.mainimageview]; self.buttontraining.backgroundcolor = [uicolor redcolor]; self.buttontraining.tintcolor = [uicolor whitecolor]; self.buttontraining.titlelabel.font = [uifont fontwithname:@"helveticaneue-bold" size:30]; [self.buttontraining settitle:nslocalizedstring(@"training", nil) forstate:uicontrolstatenormal]; [self.buttontraining sizetofit];  if (self.view.frame.size.height <= 480) {     self.buttontraining.frame = cgrectmake(0, self.mainimageview.frame.origin.y + self.mainimageview.frame.size.height, self.view.frame.size.width, self.buttontraining.frame.size.height); } else {     self.buttontraining.frame = cgrectmake(0, self.mainimageview.frame.origin.y + self.mainimageview.frame.size.height, self.view.frame.size.width, self.buttontraining.frame.size.height * 2); }  [self.buttontraining addtarget:self action:@selector(starttraining) forcontrolevents:uicontroleventtouchupinside];   self.titlelabel = [uilabel new]; [self.view insertsubview:self.titlelabel abovesubview:self.mainimageview]; self.titlelabel.textcolor = [uicolor whitecolor]; self.titlelabel.font = [uifont fontwithname:@"helveticaneue" size:30]; self.titlelabel.textalignment = nstextalignmentcenter; self.titlelabel.text = @"text"; [self.titlelabel sizetofit];  self.titlelabel.frame = cgrectmake((self.view.frame.size.width - self.titlelabel.frame.size.width) / 2.0f + 18, self.navigationcontroller.navigationbar.frame.origin.y + self.navigationcontroller.navigationbar.frame.size.height + 8, self.titlelabel.frame.size.width, self.titlelabel.frame.size.height);} 

the problem couldn't manage reproduce issue! tested app on iphone simulator (iphone 4s - iphone 6 plus) provided xcode , on iphone 5 (both via connecting xcode , via distributing using ad hoc provisioning), ios 8.0-8.4. ok. i've received screenshots (app store review) no button , said doesn't appear after launching app.

uiimageview , uilabel work well.

have ideas why?! can guarantee it's place in code these ui elements affected. in advance!

i think issue lies in below code..

self.buttontraining.frame.size.height null sometimes. u setting buttontraining height or frame after creating button dynamically?

if (self.view.frame.size.height <= 480) {     self.buttontraining.frame = cgrectmake(0, self.mainimageview.frame.origin.y + self.mainimageview.frame.size.height, self.view.frame.size.width, self.buttontraining.frame.size.height); } else {     self.buttontraining.frame = cgrectmake(0, self.mainimageview.frame.origin.y + self.mainimageview.frame.size.height, self.view.frame.size.width, self.buttontraining.frame.size.height * 2); } 

so, instead of self.buttontraining.frame.size.height use static value or below

if (self.view.frame.size.height <= 480) {     self.buttontraining.frame = cgrectmake(0, self.mainimageview.frame.origin.y + self.mainimageview.frame.size.height, self.view.frame.size.width, self.mainimageview.frame.size.height);//set static value self.buttontraining.frame.size.height } else {     self.buttontraining.frame = cgrectmake(0, self.mainimageview.frame.origin.y + self.mainimageview.frame.size.height, self.view.frame.size.width, self.mainimageview.frame.size.height * 2);//set static value self.buttontraining.frame.size.height } 

once check it.. hope helps you...!


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -