iOS常用方法——一个好用的获取导航栏高度和Tabbar高度的分类

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/aaaaazq/article/details/80981367

开发中经常需要知道导航栏(系统)的高度和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

猜你喜欢

转载自blog.csdn.net/aaaaazq/article/details/80981367