1. 程式人生 > >修改系統TabBar高度、文字大小和位置

修改系統TabBar高度、文字大小和位置

1、修改tabbar高度

重寫- (void)viewWillLayoutSubviews方法

//改變tabbar高度
- (void)viewWillLayoutSubviews{
    CGRect tabFrame = self.tabBar.frame;
    tabFrame.size.height = 49;
    tabFrame.origin.y = self.view.frame.size.height - 49;
    self.tabBar.frame = tabFrame;
}

2、修改TabBarItem的文字大小和位置

使用[UITabBarItem appearance]方法,需要注意的是:如果使用 viewcontroller.tarBarItem 設定,如[viewcontroller.tarBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
那麼為TabBarItem設定的選中顏色會失效

[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -3)];
//Normal
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
//Selected
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11
]} forState:UIControlStateSelected];