【Loading Resources】iOS Supports Device-Specific Resources

In iOS 4.0 and later, it is possible to mark individual resource files as usable only on a specific type of device.This capability simplifies the code you have to write for Universal applications. Rather than creating separate code paths to load one version of a resource file for iPhone and a different version of the file for iPad, you can let the bundle-loading routines choose the correct file. All you have to do is name your resource files appropriately. 

<basename> <device> .<filename_extension> 

The <basename> string represents the original name of the resource file. It also represents the name you use when accessing the file from your code. Similarly, the <filename_extension> string is the standard filename extension used to identify the type of the file. The <device> string is a case-sensitive string that can be one of the following values:

~ipad - The resource should be loaded on iPad devices only.
~iphone - The resource should be loaded on iPhone or iPod touch devices only. 

You can apply device modifiers to any type of resource file. For example, suppose you have an image namedMyImage.png. To specify different versions of the image for iPad and iPhone, you would create resource fileswith the names MyImage~ipad.png and MyImage~iphone.png and include them both in your bundle. Toload the image, you would continue to refer to the resource as MyImage.png in your code and let the systemchoose the appropriate version, as shown here: 

<span style="font-size:18px;">UIImage* anImage = [UIImage imageNamed:@"MyImage.png"];</span>

On an iPhone or iPod touch device, the system loads the MyImage~iphone.png resource file, while on iPad,it loads the MyImage~ipad.png resource file. If a device-specific version of a resource is not found, the systemfalls back to looking for a resource with the original filename, which in the preceding example would be animage named MyImage.png


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值