Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position a UIView relative to the bottom of the parent view?

How can I align a UIView to the bottom of the parent so that the Y coordinate of the frame is relative to the bottom of the screen instead of the top?

This would be the equivalent to setting the .bottom property in HTML.

This is because I want to make sure my view is always at the bottom of window regardless of the height of the parent.

like image 828
Camsoft Avatar asked Nov 24 '11 13:11

Camsoft


3 Answers

Once you have initially positioned the view by setting its frame property, adjust its autoresizingMask to include UIViewAutoresizingFlexibleTopMargin. That will keep it anchored to the bottom of its superview.

like image 83
Jeff Kelley Avatar answered Nov 06 '22 02:11

Jeff Kelley


You can set the autoresizing mask values on the Sizing pane in XIB or Storyboard editor.

like image 20
Denis Avatar answered Nov 06 '22 02:11

Denis


This should do the trick

public override void ViewDidLoad()
{
    base.ViewDidLoad();
    bottomButton.Alignment = UIStackViewAlignment.Bottom;          
}
like image 1
Bobby Faruqi Avatar answered Nov 06 '22 03:11

Bobby Faruqi