Size of images for UI for different screen sizes?

為{幸葍}努か 提交于 2019-12-24 13:21:59

问题


If I want to set a button's background image in iOS in an app that uses autolayout, what size should the .png image be? Since the height, and width of the button will always vary, in addition to accommodating for retina/nonretina displays (@2x?).


回答1:


You can add multiple images with providing proper naming conventions normal, @2x, @3x, ~iPad etc.

For that go through Apple documentations. For example, your image name is myBackground.png then

[UIImage imageForDeviceWithName:@"myBackground"];

Then here is the list of files and resolutions for "myBackground"

myBackground@2x.png == 960 × 640

myBackground-568h@2x.png == 1136 × 640

myBackground-667h@2x.png == 1334 × 750

myBackground@3x.png == 2208 × 1242

myBackground~ipad.png == 1024 × 768

myBackground@2x~ipad.png == 2048 × 1536

Same way you require to add images for landscape with suffix added like: ~Landscape




回答2:


When You are using Image for particular Button then you should note down the following point

  • When your Button is size of 50x100 then the Image should be with size 50x100 for non-ratina. and Button is size of 50x100 then the Image should be with size 100x200 for Ratina.

In short doesn't matter with your Button size. when you are using any Image with X size for Non Ratina then for Ratina display required same Image with 2X (double size) image.

X size for Non Ratina

2*x size for Ratina

because it will work every device but your Button Image will not seen properly.



来源:https://stackoverflow.com/questions/27741808/size-of-images-for-ui-for-different-screen-sizes

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