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

25,701

Solution 1

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.

Solution 2

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

Solution 3

This should do the trick

public override void ViewDidLoad()
{
    base.ViewDidLoad();
    bottomButton.Alignment = UIStackViewAlignment.Bottom;          
}
Share:
25,701
Camsoft
Author by

Camsoft

Updated on July 10, 2022

Comments

  • Camsoft
    Camsoft almost 2 years

    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.

  • Camsoft
    Camsoft over 12 years
    Almost worked, had to set the view's frame Y coordinate to a negative number to pull the view up from the bottom.
  • user3344977
    user3344977 about 9 years
    Amazingly simple and still works perfectly in iOS 8.
  • Dushi Fdz
    Dushi Fdz about 9 years
    In iOS 8, you can use Auto Layout, which is a much better way of expressing this need, but is way beyond the scope of this answer. :)