How to proportinally size the image based on the iphone is using

本秂侑毒 提交于 2020-01-06 01:29:26

问题


Let say I have a large image (400wx700h) pixels. I want this image to be centered on the iphone and take 1/4 of the display area. Doesn't matter if is iphone 4 or iphone 6+, I still want this image to be centered and take only 1/4 of the display area. Also, I want to design this in storyboard and using constraints, with no coding. I know how to center the image, but not sure about the 1/4 portion. Can someone please guide me?

Thanks Borna


回答1:


Create constraints for equal width and height with the super view, and set the multiplier in each constraint to 0.25




回答2:


  1. Use a UIImageView to contain your UIImage.
  2. Set the imageView.contentMode to ScaleToFit

  3. Use the Equals Widths and Equals Heights constraints from the imageView to your viewController's view.

  4. Use the multiplier (4 with Inverse Multiplier) on the constraints to adjust the size to what you want.



来源:https://stackoverflow.com/questions/30924523/how-to-proportinally-size-the-image-based-on-the-iphone-is-using

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