iPhone12 屏幕适配

.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, iPhoneType) {
    iPhoneTypeiPhone4,
    iPhoneTypeiPhone5,
    iPhoneTypeiPhone,
    iPhoneTypeiPhonePlus,
    iPhoneTypeiPhoneMini,  // 这里开始刘海屏
    iPhoneTypeiPhoneXR,
    iPhoneTypeiPhoneX_XS,
    iPhoneTypeiPhonePro,
    iPhoneTypeiPhoneMax,
    iPhoneTypeiPhoneProMax,
    iPhoneTypeiPad,
    iPhoneTypeiPad3rd,
    iPhoneTypeUnkuown
};

NS_ASSUME_NONNULL_BEGIN

@interface IphoneMnanager : NSObject

/// 获取设备型号
+(iPhoneType)iphone;

/// 导航条高度
+(CGFloat)navgationBerHeight;

/// 标签栏高度
+(CGFloat)statusBerHeight;

/// 是否为刘海屏
+(BOOL)isliuHaiPing;

@end

NS_ASSUME_NONNULL_END

.m

#import "IphoneMnanager.h"

@implementation IphoneMnanager

+(iPhoneType)iphone
{
    BOOL ipad   = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
    CGSize size = [[UIScreen mainScreen] currentMode].size;
    CGFloat w   = size.width;
    CGFloat h   = size.height;
    iPhoneType type = iPhoneTypeUnkuown;
    if (ipad == YES)
    {
        type = iPhoneTypeiPad;
    }
    else
    {
        if (w == 640 && h == 960) {
            type = iPhoneTypeiPhone4;
        }else if (w == 640 && h == 1136){
            type = iPhoneTypeiPhone5;
        }else if (w == 750 && h == 1134){
            type = iPhoneTypeiPhone;
        }else if (w == 1242 && h == 2208){
            type = iPhoneTypeiPhonePlus;
        }else if (w == 1080 && h == 2340){
            type = iPhoneTypeiPhoneMini;
        }else if (w == 828 && h == 1792){
            type = iPhoneTypeiPhoneXR;
        }else if (w == 1125 && h == 2436){
            type = iPhoneTypeiPhoneX_XS;
        }else if (w == 1170 && h == 2532){
            type = iPhoneTypeiPhonePro;
        }else if (w == 1242 && h == 2688){
            type = iPhoneTypeiPhoneMax;
        }else if (w == 1284 && h == 2778){
            type = iPhoneTypeiPhoneProMax;
        }else{
            type = iPhoneTypeUnkuown;
        }
    }
    return type;
}

+(CGFloat)navgationBerHeight
{
    iPhoneType type =  [self iphone];
    switch (type) {
        case iPhoneTypeiPhone4 ... iPhoneTypeiPhonePlus:
        {
            return 64.f;
        }
            break;
        case iPhoneTypeiPhoneMini ... iPhoneTypeiPhoneProMax:
        {
            return 88.f;
        }
            break;
        default:
            return 64.f;
            break;
    }
}

+(CGFloat)statusBerHeight
{
    iPhoneType type =  [self iphone];
    switch (type) {
        case iPhoneTypeiPhone4 ... iPhoneTypeiPhonePlus:
        {
            return 20.f;
        }
            break;
        case iPhoneTypeiPhoneMini ... iPhoneTypeiPhoneProMax:
        {
            return 44.f;
        }
            break;
        default:
            return 20.f;
            break;
    }
}

+(BOOL)isliuHaiPing
{
    iPhoneType type =  [self iphone];
    switch (type) {
        case iPhoneTypeiPhone4 ... iPhoneTypeiPhonePlus:
        {
            return NO;
        }
            break;
        case iPhoneTypeiPhoneMini ... iPhoneTypeiPhoneProMax:
        {
            return YES;
        }
            break;
        case iPhoneTypeiPad:
        {
            return NO;
        }
            break;
        default:
            return YES;
            break;
    }
}

@end

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值