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

那年仲夏 提交于 2019-12-24 13:54:06

问题


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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/35641944/what-do-you-apply-auto-layout-constraints-to-line-up-labels-with-background-imag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!