DennisTurn February 2016

Constraints on UILabel not working

I've been struggling for the past hour with constraints in Swift. I can't for the life in me get my labels to look exactly how they do in the storyboard.

I currently have vertical spacing, and horizontal spacing on both my labels.

How it looks when loaded up:

Screen shot when running

How it looks in the storyboard:

Screen shot of storyboard

I'm using auto-layout but not size classes.

Any help is appreciated, constraints should be easy but they are a living hell.

Answers


Duncan C February 2016

I'm not sure what you mean when you say "I currently have vertical spacing, and horizontal spacing on both my labels."

To get the look you show I would select the 2 labels and choose editor>enclose in>view. Then set the spacing between the 2 labels to a constant value, and finally, select the new grouping view and center it horizontally in it's parent view.


Peter February 2016

You can put both labels into a UIView.

Next put the UIView in the center of the page. Add "Horizontally in container", "Width", "Height", and "Top Space" constraints to the UIView.

Post Status

Asked in February 2016
Viewed 3,250 times
Voted 5
Answered 2 times

Search




Leave an answer