//此方法只会调用一次,设置UIBarButtonItem样式 +(void)initialize { //通过appearance对象能修改整个项目中所有UIBarButtonItem的样式 UIBarButtonItem *appearance = [UIBarButtonItem appearance]; //1.普通状态 NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; textAttrs[UITextAttributeTextColor] = [UIColor orangeColor]; textAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:15]; [appearance setTitleTextAttributes:textAttrs forState:UIControlStateNormal]; //2.高亮状态 NSMutableDictionary *highAttrs = [NSMutableDictionary dictionary]; highAttrs[UITextAttributeTextColor] = [UIColor redColor]; highAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:15]; [appearance setTitleTextAttributes:highAttrs forState:UIControlStateHighlighted]; //3.不可点击状态 NSMutableDictionary *disAttrs = [NSMutableDictionary dictionary]; disAttrs[UITextAttributeTextColor] = [UIColor lightGrayColor]; disAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:15]; [appearance setTitleTextAttributes:disAttrs forState:UIControlStateDisabled]; } //页面跳转会调用这个方法 -(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { //self.viewControllers.count 控制器栈中控制器数量 if (self.viewControllers.count > 0) { //隐藏标签栏 viewController.hidesBottomBarWhenPushed = YES; // 全局设置导航栏按钮 viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"navigationbar_back" highImageName:@"navigationbar_back_highlighted" target:self action:@selector(back)]; viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImageName:@"navigationbar_more" highImageName:@"navigationbar_more_highlighted" target:self action:@selector(more)]; } [super pushViewController:viewController animated:animated]; }
时间: 2024-11-04 16:24:15