Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 6 Storyboard can't center

I have an issue trying to center an object in a storyboard. I've created a new "Single-view Application" project, entered a main.Storyboard and I'm trying to add a label to center of it. On a preview of this storyboard for 4-inch iPhone, the label isn't centered, even when I force storyboard to use 3.5, 4, or 4.7-inch iPhones. Adding constraints makes no difference. What am I doing wrong?

like image 271
Artem Zaytsev Avatar asked Dec 01 '22 18:12

Artem Zaytsev


2 Answers

If you want to center the label vertically and horizontally, you can use Align option at the storyboard. On your storyboard's bottom right corner, there are four options and the first one is Align option, selecting it will give you to choose the alignment for your object as follows,

Alignment option

Here in the screenshot, you can see that I have selected two options if I want to center my object in both dimension. You can choose either one of them or both based on your requirements and press Add 2 constraints button and it will work consistently for any sized screen. However make sure to select the object you want to center before selecting the Align option.

like image 70
ldindu Avatar answered Dec 10 '22 21:12

ldindu


Try using the reset to suggested constraints. It works quite well for simple layout. Otherwise, you just have to fine tune your constraints reset to suggested constraints.

like image 32
Kalenda Avatar answered Dec 10 '22 22:12

Kalenda