[iOS功能]- iOS 宏定义状态栏、导航栏、tabBar高度

//获取状态栏的高度
CGFloat statusHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
NSLog(@"状态栏高度:%f",statusHeight);

//获取导航栏的高度
CGFloat navHeight = self.navigationController.navigationBar.frame.size.height;
NSLog(@"导航栏高度:%f",navHeight);

//获取tabBar的高度
//1.在tabBarController中使用(你的继承自UITabBarController的VC)
CGFloat tabBarHeight = self.tabBar.frame.size.height;
NSLog(@"tabBar高度:%f",tabBarHeight);
//2.在非tabBarController中使用
UITabBarController *tabBarVC = [[UITabBarController alloc] init];//(这儿取你当前tabBarVC的实例)
CGFloat tabBarHeight = tabBarVC.tabBar.frame.size.height;
NSLog(@"tabBar高度:%f",tabBarHeight);
define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define mc_Is_iphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define mc_Is_iphoneX SCREEN_WIDTH >=375.0f && SCREEN_HEIGHT >=812.0f&& mc_Is_iphone
    
/*状态栏高度*/
#define mcStatusBarHeight (CGFloat)(mc_Is_iphoneX?(44.0):(20.0))
/*导航栏高度*/
#define mcNavBarHeight (44)
/*状态栏和导航栏总高度*/
#define mcNavBarAndStatusBarHeight (CGFloat)(mc_Is_iphoneX?(88.0):(64.0))
/*TabBar高度*/
#define mcTabBarHeight (CGFloat)(mc_Is_iphoneX?(49.0 + 34.0):(49.0))
/*顶部安全区域远离高度*/
#define mcTopBarSafeHeight (CGFloat)(mc_Is_iphoneX?(44.0):(0))
 /*底部安全区域远离高度*/
#define mcBottomSafeHeight (CGFloat)(mc_Is_iphoneX?(34.0):(0))
/*iPhoneX的状态栏高度差值*/
#define mcTopBarDifHeight (CGFloat)(mc_Is_iphoneX?(24.0):(0))
/*导航条和Tabbar总高度*/
#define mcNavAndTabHeight (mcNavBarAndStatusBarHeight + mcTabBarHeight)

你可能感兴趣的:([iOS功能]- iOS 宏定义状态栏、导航栏、tabBar高度)