Aspect ratio constraint relative to the screen width

随声附和 提交于 2019-12-12 05:18:05

问题


I have set a cell image to my UITableViewCell. It is a custom cell. I have set the aspect ratio as 1:1 and the width of the image view to 50. But for iphone 5 and 5s this size is too big as I feel. So how can I change the size of the UIImageView relative to the screen width. Please help me. Thanks

This is my current view


回答1:


There are at least 2 ways you could configure image size based on the screen size:

  • Size-Classes allows you to set different width constraint value based on Trait Variation: Compact or Regular. Just select the width constraint, click on the Plus button on the left of it's Constant value and add a new variation for the iPhone device screens.

  • Manual approach with Aspect Ration constraint. This way you should select both ImageView and cell's ContentView, create "Equal Width" constraint and change it's multiplier value. Start with a 1:5 value - looking good.



来源:https://stackoverflow.com/questions/44941325/aspect-ratio-constraint-relative-to-the-screen-width

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