1、标签控制器的相关设置
// 设置正常状态下的属性字典
NSDictionary *normalDic = [NSDictionary dictionary];
normalDic = @{NSFontAttributeName:[UIFont systemFontOfSize:12],
NSForegroundColorAttributeName:[UIColor grayColor]
};
// 设置高亮状态下的属性字典
NSDictionary *heigthDic = [NSDictionary dictionary];
heigthDic = @{NSForegroundColorAttributeName:[UIColor darkGrayColor],
NSFontAttributeName:[UIFont systemFontOfSize:12]
};
2、 通过appearance统一设置UITabBaiItem的文字属性
注意:后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearance对象来统一设置
UITabBarItem *item = [UITabBarItem appearance];
// 普通状态下
[item setTitleTextAttributes:normalDic forState:UIControlStateNormal];
// 高亮状态下
[item setTitleTextAttributes:heigthDic forState:UIControlStateHighlighted];
// 设置控制器相关属性
3、 通过封装方法来设置子控制的相关属性,减少代码冗余量
-(void)setChildVc:(UIViewController *)vc withTitle:(NSString *)title withImage:(NSString *)image withSelectedImage:(NSString *)selectedImage{
//设置控制器的标题和图片属性
vc.tabBarItem.title = title;
vc.tabBarItem.image = [UIImage imageNamed:image];
vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
// 设置背景颜色
vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
// 添加子控制器
[self addChildViewController:vc];
// 设置正常状态下的属性字典
NSDictionary *normalDic = [NSDictionary dictionary];
normalDic = @{NSFontAttributeName:[UIFont systemFontOfSize:12],
NSForegroundColorAttributeName:[UIColor grayColor]
};
// 设置高亮状态下的属性字典
NSDictionary *heigthDic = [NSDictionary dictionary];
heigthDic = @{NSForegroundColorAttributeName:[UIColor darkGrayColor],
NSFontAttributeName:[UIFont systemFontOfSize:12]
};
2、 通过appearance统一设置UITabBaiItem的文字属性
注意:后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearance对象来统一设置
UITabBarItem *item = [UITabBarItem appearance];
// 普通状态下
[item setTitleTextAttributes:normalDic forState:UIControlStateNormal];
// 高亮状态下
[item setTitleTextAttributes:heigthDic forState:UIControlStateHighlighted];
// 设置控制器相关属性
3、 通过封装方法来设置子控制的相关属性,减少代码冗余量
-(void)setChildVc:(UIViewController *)vc withTitle:(NSString *)title withImage:(NSString *)image withSelectedImage:(NSString *)selectedImage{
//设置控制器的标题和图片属性
vc.tabBarItem.title = title;
vc.tabBarItem.image = [UIImage imageNamed:image];
vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
// 设置背景颜色
vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
// 添加子控制器
[self addChildViewController:vc];
}
注意:导航栏的设置补充(因为之前写过导航栏的相关设置,所以这里是补充之前没涉及到的)
4、用图片设置导航栏的标题
self.navigationItem.titleView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"MainTitle"]];
5、自定义导航栏
// 当第一次使用这个类的时候会调用一次
+(void)initialize{
UINavigationBar *bar = [UINavigationBar appearance];
[bar setBackgroundImage:[UIImage imageNamed:@“1.jpg”] forBarMetrics:UIBatMetricsDefault];
}
// 可以在这个方法中设置所有push进来的控制器
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
}