//
// MyNavigationController.m// 新浪微博
//
// Created by jose on 15-3-12.
// Copyright (c) 2015年 jose. All rights reserved.
//
#import "MyNavigationController.h"
#import "UIBarButtonItem+Extension.h"
@interface MyNavigationController ()
@end
@implementation MyNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//重写该方法
//第一次调用该类的时候,会调用一次该方法
+(void)initialize{
[self setupBarButtonItemTheme];
[self setupNavigationBarTheme];
}
//设置setupNavigation的主题(静态方法)
+ (void)setupNavigationBarTheme{
//1.获取对象
UINavigationBar *appearance=[UINavigationBar appearance];
//2.保存
NSMutableDictionary *TextAttribute=[NSMutableDictionary dictionary];
//3.设置文字色彩
TextAttribute[NSForegroundColorAttributeName]=[UIColor blackColor];
//4.设置字体的大小
TextAttribute[NSFontAttributeName]=[UIFont systemFontOfSize:20];
//设置字体偏移量
//TextAttribute[UITextAttributeTextShadowOffset]=[NSValue valueWithUIOffset:UIOffsetZero];
//5.设置属性
[appearance setTitleTextAttributes:TextAttribute];
}
//设置BarButtonItem的主题
+(void)setupBarButtonItemTheme{
//获取能修改文字属性的对象
UIBarButtonItem *appearance=[UIBarButtonItem appearance];
//1.设置普通状态下的文字属性
NSMutableDictionary *TextAttribute=[NSMutableDictionary dictionary];
TextAttribute[NSForegroundColorAttributeName]=[UIColor orangeColor];
TextAttribute[NSFontAttributeName]=[UIFont systemFontOfSize:15];
[appearance setTitleTextAttributes:TextAttribute forState:UIControlStateNormal];
//2.设置高亮状态下的文字属性
NSMutableDictionary *HighTextAttribute=[NSMutableDictionary dictionaryWithDictionary:TextAttribute];
HighTextAttribute[NSForegroundColorAttributeName]=[UIColor redColor];
[appearance setTitleTextAttributes:HighTextAttribute forState:UIControlStateHighlighted];
//3.设置不可用状态下的文字
NSMutableDictionary *DisableTextAttribute=[NSMutableDictionary dictionaryWithDictionary:TextAttribute];
DisableTextAttribute[NSForegroundColorAttributeName]=[UIColor lightGrayColor];
[appearance setTitleTextAttributes:DisableTextAttribute forState:UIControlStateDisabled];
//设置背景
//技巧提示:为了让某个按钮的背景消失,可以设置一张完全透明的背景图片
//[appearance setBackButtonBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"]forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}
#pragma mark
//拦截导航控制器
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
//如果push的不是栈顶控制器,则隐藏底部工具栏
if (self.viewControllers.count>0) {
viewController.hidesBottomBarWhenPushed=YES;
viewController.navigationItem.leftBarButtonItem=[UIBarButtonItem img:@"navigationbar_back@2x" highimg:@"navigationbar_back_highlighted@2x" target:self action:@selector(back)];
viewController.navigationItem.rightBarButtonItem=[UIBarButtonItem img:@"navigationbar_more@2x" highimg:@"navigationbar_more_highlighted@2x" target:self action:@selector(more)];
}
[super pushViewController:viewController animated:YES];
}
-(void)back{
[self popViewControllerAnimated:YES];
}
-(void)more{
[self popToRootViewControllerAnimated:YES];
}
@end