1. 程式人生 > >iOS常用方法——一個好用的獲取導航欄高度和Tabbar高度的分類

iOS常用方法——一個好用的獲取導航欄高度和Tabbar高度的分類

開發中經常需要知道導航欄(系統)的高度和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