0

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.

MQ.
  • 365
  • 6
  • 28

2 Answers2

3

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];
Pradip Vanparia
  • 1,742
  • 10
  • 22
0

Please try with this.

UIButton *pickmeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 60, [UIScreen mainScreen].bounds.size.width, 60)];
VD Patel
  • 286
  • 1
  • 6