简体   繁体   English

如何在Swift中使用故事板将UIView居中

[英]How to center a UIView using storyboard in Swift

I have a view inside another view which I create using storyboard, now I want to position my inner view center vertically. 我在使用情节提要创建的另一个视图中有一个视图,现在我想垂直放置内部视图的中心。 How can I achieve that? 我该如何实现?

First select the View and place in center of the nib,Then Tick the Horizontal Center in Container and Vertical Center in Container 首先选择“视图”并放置在笔尖的中心,然后在“容器”中勾选“水平中心”并在“容器”中勾选“垂直中心”

在此处输入图片说明

Then Give Height and Width to the View,Your View is now centered. 然后将“高度”和“宽度”赋予视图,您的视图现在居中。

在此处输入图片说明

Use NSLayoutConstraint (Center Horizontally, Center Vertically) with parent view. 将NSLayoutConstraint(水平居中,垂直居中)与父视图一起使用。 And you need set constraint (width, height) for this view. 并且您需要为此视图设置约束(宽度,高度)。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在自定义 UIView(Storyboard Swift)中居中 VideoPreviewLayer - How To Center VideoPreviewLayer in Custom UIView (Storyboard Swift) 如何更改故事板中添加的UIView的中心? - How to change center of UIView, added in storyboard? 如何快速将故事板置于表格视图上方的中心位置? - How to center a button above a tableview with the storyboard in swift? 如何在Swift 3.0中以编程方式使用autolayout在UIView容器内水平居中2个或更多UIViews - How to center horizontally 2 or more UIViews inside a UIView container using autolayout programmatically in Swift 3.0 如何使用iOS在故事板上创建ImageView中心? - How to create ImageView center on storyboard using iOS? 如何使用Swift在屏幕中心水平或垂直设置UIImageView,但不再使用StoryBoard - How to set UIImageView in the center of screen horizontally or vertically with Swift, but no more StoryBoard 使用自动布局约束Swift 2.1从中心到顶部对UIView进行动画处理 - Animate UIView from center to top using autolayout constraings swift 2.1 swift 3:如何在UIView上对齐(垂直和水平)UIButton? - swift 3: How to center align (vertically & horizontally) UIButton on UIView? 在情节提要的UIView中使用子类 - Using a subclass in storyboard's UIView 更改情节提要中已经存在的UIView的宽度? 迅速 - Change the width of a UIView that already exists in Storyboard? Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM