ios 相对于父视图的底部定位 UIView?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8258216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Position a UIView relative to the bottom of the parent view?
提问by Camsoft
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?
如何将 UIView 与父级底部对齐,以便框架的 Y 坐标相对于屏幕底部而不是顶部?
This would be the equivalent to setting the .bottom property in HTML.
这相当于在 HTML 中设置 .bottom 属性。
This is because I want to make sure my view is always at the bottom of window regardless of the height of the parent.
这是因为我想确保无论父级的高度如何,我的视图始终位于窗口的底部。
回答by Jeff Kelley
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.
通过设置其frame
属性来初始定位视图后,将其调整autoresizingMask
为 include UIViewAutoresizingFlexibleTopMargin
。这将使其锚定在其父视图的底部。
回答by Denis
You can set the autoresizing mask values on the Sizing pane in XIB or Storyboard editor.
您可以在 XIB 或 Storyboard 编辑器的 Sizing 窗格上设置自动调整大小掩码值。
回答by Bobby Faruqi
This should do the trick
这应该可以解决问题
public override void ViewDidLoad()
{
base.ViewDidLoad();
bottomButton.Alignment = UIStackViewAlignment.Bottom;
}