如何将图像资源用于不同尺寸的iphone

时间:2015-02-02 09:45:00

标签: ios objective-c xcode image

我想知道如何在xcode中管理不同尺寸iphone的图像资源,假设我有iphone 5的图像名称abc.png abc.png非20X20 abc@2x.png 40X40

因为我可以在xib中设置图像名称abc.png但是因为iphone 6和iphone 6+的大小不同所以我如何使用abc.png来制作那些大尺寸的iphone

I have images for all resolutions
abc.png (for iphone 5)
abc6.png (for iphone 6)
abc6plus.png (for iphone 6+)

i have below doubts in my mind 

1. i have to mannualy set image in code for iphone6 and iphone 6+ by checking the screen size?if yes then please let me know do i have to use only one image that is 1X or have to add 2X image also for all device 

2.i think that as these iphone5,iphone 6 and iphone6Plus are retina displays so i should use only 2X images for these displays?

3.Do we have to use images like giving then name of image in xib abc.png and placing the abc@2x.png for iphone 6 and abc@3x.png for iphone6+ in bundle only and xcode will pick corresponding image at runtime?

请建议

2 个答案:

答案 0 :(得分:0)

您可以使用UIImageAsset

UIImageAsset对象是一组图像的容器,表示描述单件艺术品的多种方式。 UIImageAsset的一个常见用例是在不同的显示比例下对同一项目的多个图像进行分组。

答案 1 :(得分:0)

正如你所说

  

3.我们是否必须在xib abc.png中使用图像名称,然后将ic 6的abc@2x.png和abc@3x.png放在一起   只有捆绑的iphone6 +和xcode将选择相应的图像   运行

你只需要在资产中添加相同图像的不同分辨率(Images.xcassets)(即abc.png,abc @ 2x.png和abc@3x.png)其余的工作将由资产和xcode自动完成

看看这个

iPhone 6 Plus resolution confusion: Xcode or Apple's website? for development