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

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”




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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值