Member-only story

Center Constraints (AutoLayout iOS)

Mr.Javed Multani
3 min readOct 3, 2020

--

Select your button (or whatever view you want to center) on the storyboard. Then click the align button on the bottom right. Select Horizontally in Container and Vertically in Container. Click “Add 2 Constraints”.

If it wasn’t perfectly centered already, you may need to do one more thing. Click the “Update Frames” button that is two to the left of the “Embed In Stack” button on the bottom bar.

You can also “update frames as necessary” by pressing together + + = (Command + Option and equals) after selecting the view, this might save some time.

Now when you run your app it should be centered, no matter what device size you are using.

Another way to center views using Interface Builder is by control-click-dragging. Say you want to center a UILabel in a view. Open the Document Outline in your storyboard by clicking the sidebar button at the bottom left. Click and drag from the label to the view while holding ctrl (control), and a blue line should appear:

--

--

Mr.Javed Multani
Mr.Javed Multani

Written by Mr.Javed Multani

Software Engineer | Certified ScrumMaster® (CSM) | UX Researcher | Youtuber | Tech Writer

No responses yet