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

时间:2022-11-19 10:20:19

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];