I want to pin a UIButton to bottom right corner of the iPhone screen. Both in 3.5inch and 4inch screens.
Here is the code I wrote. But the button always stays on x=265,y=361 both in iPhone4 and iPhone5.
UIImage* plusImage = [UIImage imageNamed:@"Plus.png"];
UIButton* plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[plusButton setImage:plusImage forState:UIControlStateNormal];
[plusButton setFrame:CGRectMake(265, 361, plusImage.size.width, plusImage.size.height)];
plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:plusButton];
I've set the autoresizing masks to take flexible top and left margins.But it didnt work. What did I miss? Please help.
UIImage* plusImage = [UIImage imageNamed:@"Plus.png"];
UIButton* plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[plusButton setImage:plusImage forState:UIControlStateNormal];
CGSize viewSize = self.view.frame.size;
[plusButton setFrame:CGRectMake(viewSize.width - plusImageSize.width, viewSize.height - plusImageSize.height, plusImage.size.width, plusImage.size.height)];
plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:plusButton];
Try that instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With