您的位置:首页 > 移动开发 > IOS开发

[iOS学习]设置iPhone5 5s6背景图

2015-06-02 22:25 387 查看
1. 屏幕大小问题点

随着iOS的碎片化,特别是 4/4s/5/5s/6/6p出来后,每个屏幕的高度宽度都不一样,如果背景图片不具有拉伸平铺的性质,

则同时@2x图的4/4s/5/5s/6 的图片将被压缩或拉伸。

关于iOSLauchImage画面适应iPhone5 iPhone5s iPhone6 iPhone6P分辨率的介绍有很多,比如将LaunchImage设置成

多个分辨率,具体请参照。

2.背景图的设置方法。

一般采用屏幕大小去判断是哪种苹果机型如一下代码:

#import "BXDevice.h"

@implementation BXDevice

+(thisDeviceClass) currentDeviceClass {

CGFloat greaterPixelDimension = (CGFloat) fmaxf(((float)[[UIScreen mainScreen]bounds].size.height),
((float)[[UIScreen mainScreen]bounds].size.width));

switch ((NSInteger)greaterPixelDimension) {
case 480:
return (( [[UIScreen mainScreen]scale] > 1.0) ? thisDeviceClass_iPhoneRetina : thisDeviceClass_iPhone );
break;
case 568:
return thisDeviceClass_iPhone5;
break;
case 667:
return thisDeviceClass_iPhone6;
break;
case 736:
return thisDeviceClass_iPhone6plus;
break;
case 1024:
return (( [[UIScreen mainScreen]scale] > 1.0) ? thisDeviceClass_iPadRetina : thisDeviceClass_iPad );
break;
default:
return thisDeviceClass_unknown;
break;
}
}

+ (NSString *)magicSuffixForDevice
{
switch ([BXDevice currentDeviceClass]) {
case thisDeviceClass_iPhone:
return @"";
break;
case thisDeviceClass_iPhoneRetina:
return @"@2x";
break;
case thisDeviceClass_iPhone5:
return @"-568h@2x";
break;
case thisDeviceClass_iPhone6:
return @"-667h@2x"; //or some other arbitrary string..
break;
case thisDeviceClass_iPhone6plus:
return @"-736h@3x";
break;

case thisDeviceClass_unknown:
default:
return @"";
break;
}
}

+(UIImage *)imageDeviceWithName:(NSString *)fileName
{
UIImage *result = nil;
NSString *nameWithSuffix = [fileName stringByAppendingString:[BXDevice magicSuffixForDevice]];

result = [UIImage imageNamed:nameWithSuffix];
if (!result) {
result = [UIImage imageNamed:fileName];
}
return result;
}

@end


还有一种方法是通过系统的参数去判断
struct utsname systemInfo;
uname(&systemInfo);

NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];


这个platform的值比较杂乱,其中iphone6 得到的是”iPhone7,2“ 而iphone6P得到的是“iphone7,1”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: