Search code examples
iosobjective-ciphoneuibuttonprogrammatically-created

My button not appears to correct position when viewController is refreshed


I am creating a simple UIButton programmatically with this frame size

UIButton *pickmeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 100, self.view.bounds.size.width, 60)];

it display at perfect place where i want

enter image description here

But on some action i want to reload the whole view controller, when i do it display the button at wrong coordinates

enter image description here

First, i am unable to find the reason for it. Second, what i think according to coordinates i have defined i think the second image is rendering the correct coordinates because, placement on Y coord is (self.view.bounds.size.height - 100) and height is 60. But when i make it -60 it starts displaying button below bottom line and very little of button shows up above.

Kindly share your views and solution on this.


Solution

  • Set AutoresizingMask for button

     UIButton *pickmeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 60, self.view.bounds.size.width, 60)];
     [pickmeButton setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];