1棒卷、修改tabbar高度
- 重寫(xiě)- (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 設(shè)置榄笙,如[viewcontroller.tarBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
那么為TabBarItem設(shè)置的選中顏色會(huì)失效
+ (void)initialize {
// 通過(guò)appearance統(tǒng)一設(shè)置所有UITabBarItem的文字屬性
// 后面帶有UI_APPEARANCE_SELECTOR的方法,都可以通過(guò)appearance對(duì)象來(lái)統(tǒng)一設(shè)置
// 正常情況下的屬性
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
attrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#666666"];
// 選中情況下的屬性
NSMutableDictionary *attrsSelected = [NSMutableDictionary dictionary];
attrsSelected[NSFontAttributeName] = attrs[NSFontAttributeName];
attrsSelected[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#28D769"];
UITabBarItem *item = [UITabBarItem appearance];
[item setTitleTextAttributes:attrs forState:UIControlStateNormal];
[item setTitleTextAttributes:attrsSelected forState:UIControlStateSelected];
[UITabBar appearance].translucent = NO;
[[UITabBar appearance]setBackgroundImage:WTVImage(@"icon_tabbarImage")];
//設(shè)置title的位置
[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -3)];
}