Brad W. Allen
Brad W. Allen

Reputation: 15

What do you apply auto layout constraints to line up labels with background image elements?

See the screenshot below for the example but here is the issue. I have 3 text labels and I'm trying to line those labels up with 3 circles that are part of an Image View. It appears the issue is caused when the image is set to Aspect Fit and gets scaled along with the various iPhone sizes. I can align the text labels horizontally but I cannot figure out how to set the vertical constraints to "scale" properly. Any suggestions or direction would be awesome, thanks!

enter image description here

Upvotes: 1

Views: 224

Answers (2)

Ben Patch
Ben Patch

Reputation: 1223

Control drag from the label to the image and you will get a list of constraint options. Select the "Center Vertically" and "Center Horizontally" options. Then the label will be constrained to the center of the image like you want. It works. See the attached images; I did it on an iPhone 6s as well as an iPad Pro just to show that it will scale with any size. Example Image on iPad ProExample Image on iPhone 6sCommand Drag from Label to ImageView Options

Upvotes: 0

J.Wang
J.Wang

Reputation: 1236

Are you setting constant for your vertical constraint? Try to set the vertical constraint against the height of the view. One way to achieve this is to set the Center horizontally constraint and change the multiplier to 1.8 or something that suits.

Upvotes: 1

Related Questions