简体   繁体   中英

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. And you need set constraint (width, height) for this view. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM