开发中经常需要知道导航栏(系统)的高度和Tabbar的高度,一般是用来计算在ViewController中的位置和高度,我们可以写一个UIVIewController的分类,这样在调用的时候就很方便。代码如下:
#import "UIViewController+MYViewControllerBar.h"
@implementation UIViewController (MYViewControllerBar)
-(float)mStatusbarHeight{
//状态栏高度
return [[UIApplication sharedApplication] statusBarFrame].size.height;
}
-(float)mNavigationbarHeight{
//导航栏高度+状态栏高度
return self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height;
}
-(float)mTabbarHeight{
//Tabbar高度
return self.tabBarController.tabBar.bounds.size.height;
}
@end

本文介绍了一种简便的方法来获取iOS应用中导航栏和Tabbar的高度,通过创建UIViewController的一个分类,使得开发者可以在ViewController中轻松地计算这些元素的位置与高度。

1718

被折叠的 条评论
为什么被折叠?



