iOS 宏定义-获取状态栏、导航栏、tabBar高度
iOS 宏定义-获取状态栏、导航栏、tabBar高度
获取状态栏、导航栏、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);
宏定义状态栏、导航栏、tabBar高度
#definekIs_iphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)#definekIs_iPhoneX kScreenWidth >=375.0f && kScreenHeight >=812.0f&& kIs_iphone/*状态栏高度*/#definekStatusBarHeight (CGFloat)(kIs_iPhoneX?(44.0):(20.0))/*导航栏高度*/#definekNavBarHeight (44)/*状态栏和导航栏总高度*/#definekNavBarAndStatusBarHeight (CGFloat)(kIs_iPhoneX?(88.0):(64.0))/*TabBar高度*/#definekTabBarHeight (CGFloat)(kIs_iPhoneX?(49.0 + 34.0):(49.0))/*顶部安全区域远离高度*/#definekTopBarSafeHeight (CGFloat)(kIs_iPhoneX?(44.0):(0))/*底部安全区域远离高度*/#definekBottomSafeHeight (CGFloat)(kIs_iPhoneX?(34.0):(0))/*iPhoneX的状态栏高度差值*/#definekTopBarDifHeight (CGFloat)(kIs_iPhoneX?(24.0):(0))/*导航条和Tabbar总高度*/#definekNavAndTabHeight (kNavBarAndStatusBarHeight + kTabBarHeight)