有关TabBar的一些性质
// 计入导航控制器时,要使得底部的TabBar消消失
test.hidesBottomBarWhenPushed = YES;
/**
* 布局子控件
*/
- (void)layoutSubviews
{
[super layoutSubviews];
// NSClassFromString(@"UITabBarButton") == [UITabBarButton class]
// NSClassFromString(@"UIButton") == [UIButton class]
/**** 设置所有UITabBarButton的frame ****/
// 按钮的尺寸
CGFloat buttonW = self.frame.size.width / 5;
CGFloat buttonH = self.frame.size.height;
CGFloat buttonY = 0;
// 按钮索引
int buttonIndex = 0;
for (UIView *subview in self.subviews) {
// 过滤掉非UITabBarButton
// if (![@"UITabBarButton" isEqualToString:NSStringFromClass(subview.class)]) continue;
if (subview.class != NSClassFromString(@"UITabBarButton")) continue;
// 设置frame
CGFloat buttonX = buttonIndex * buttonW;
if (buttonIndex >= 2) { // 右边的2个UITabBarButton
buttonX += buttonW;
}
subview.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
// 增加索引
buttonIndex++;
}
/**** 设置中间的发布按钮的frame ****/
self.publishButton.frame = CGRectMake(0, 0, buttonW, buttonH);
self.publishButton.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5);
}
/////////////////////////////
// 修改控件的外观颜色
[UISwitch appearance].onTintColor = [UIColor orangeColor];
/*设置TabBarViewController控制器的颜色*/
/** 文字属性 **/
// 普通状态下的文字属性
NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:20];
normalAttrs[NSForegroundColorAttributeName] = [UIColor redColor];
// 选中状态下的文字属性
NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
selectedAttrs[NSForegroundColorAttributeName] = [UIColor greenColor];
// 创建窗口
self.window = [[UIWindow alloc] init];
self.window.frame = [UIScreen mainScreen].bounds;
// 设置根控制器
UITabBarController *tabBarVc = [[UITabBarController alloc] init];
UITableViewController *vc0 = [[UITableViewController alloc] init];
vc0.view.backgroundColor = [UIColor redColor];
vc0.tabBarItem.title = @"精华";
[vc0.tabBarItem setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
[vc0.tabBarItem setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
vc0.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
vc0.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
[tabBarVc addChildViewController:vc0];