.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