MQ.
MQ.

Reputation: 375

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.

Upvotes: 0

Views: 93

Answers (2)

VD Patel
VD Patel

Reputation: 286

Please try with this.

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

Upvotes: 0

Pradip Vanparia
Pradip Vanparia

Reputation: 1742

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];

Upvotes: 3

Related Questions