Iphone how to build UI for both resolutions 640X960 and 320X480?

来源:互联网 发布:ieee编程语言排行榜 编辑:程序博客网 时间:2024/06/05 04:48

问:

since iPhone 4 now has 640X960 resolution i am confused how to build a proper UI for both 320 X 480 and 640 X 960 resolutions.. if i only use images and stuff of 640X960 resolution will it automatically adjust itself for smaller resolution iPhones.. if not what is the best way to differentiate on basis of device resolution??

答:

You make 2 of each image - the first one at normal scale and named the usual "whatever.png". Then you make a second hi-res version of that image at double the scale and name it "whatever@2x.png". Then, iOS will handle the rest. You'll add both of those images to the project, and anywhere in the code that you reference "whatever.png", the system will take care of grabbing and using "whatever@2x.png" when and if appropriate, so you don't have to fuss with much. That's it. Simple.

In Interface Builder, just lay things out like normal using the standard sized graphics. In code as well, just reference images as usual, referring to the standard-sized images. So long as the higher-res counterpart is named with the "@2x.png" appended, everything will just work.

So, just as an example, say you currently have a project with a button image sized 40x100 named "awesomeButton.png". To support the retina resolution, create a new button image sized at 80x200, and name it awesomeButton@2x.png. Import it into your project and iOS takes care of the rest.


原创粉丝点击