简体   繁体   中英

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:

跑步时的屏幕截图

How it looks in the storyboard:

故事板的屏幕截图

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

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

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.

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 .

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