//
// ZZNavigationController.h
// ZZ_APP主流框架
//
// Created by ZZ_Macpro on 15/10/9.
// Copyright (c) 2015年 ZZ_Macpro. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ZZNavigationController : UINavigationController
@end
//
// ZZNavigationController.m
// ZZ_APP主流框架
//
// Created by ZZ_Macpro on 15/10/9.
// Copyright (c) 2015年 ZZ_Macpro. All rights reserved.
//
#import "ZZNavigationController.h"
#import "UIBarButtonItem+ZZ.h"
@interface ZZNavigationController ()
@end
@implementation ZZNavigationController
/**
* 只创建一次
*/
+ (void)initialize
{
// 1.设置导航栏主题
[self setupNavBarTheme];
// 2.设置导航栏按钮的主题
[self setupBarButtonTheme];
}
/**
* 设置导航栏主题
*/
+ (void)setupNavBarTheme
{
// 1.获得bar对象
UINavigationBar *navBar = [UINavigationBar appearance];
// 2.判断ios7
if (!iOS7) {
// 设置bar背景
[navBar setBackgroundImage:[UIImage imageWithName:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
}
// 3.设置文字样式
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[UITextAttributeTextColor] = ZZNavigationBarTitleColor;
attrs[UITextAttributeFont] = ZZNavigationBarTitleFont;
attrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetMake(0, 0)];
[navBar setTitleTextAttributes:attrs];
}
/**
* 设置导航栏按钮的主题
*/
+ (void)setupBarButtonTheme
{
UIBarButtonItem *barItem = [UIBarButtonItem appearance];
// 1.设置按钮的背景
if (!iOS7) {
[barItem setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barItem setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_pushed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
[barItem setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_disable"] forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault];
}
// 2.设置按钮的文字样式
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[UITextAttributeTextColor] = ZZBarButtonTitleColor;
attrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetMake(0, 0)];
attrs[UITextAttributeFont] = ZZBarButtonTitleFont;
[barItem setTitleTextAttributes:attrs forState:UIControlStateNormal];
[barItem setTitleTextAttributes:attrs forState:UIControlStateHighlighted];
NSMutableDictionary *disableAttrs = [NSMutableDictionary dictionary];
disableAttrs[UITextAttributeTextColor] = ZZBarButtonTitleDisabledColor;
disableAttrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetMake(0, 0)];
[barItem setTitleTextAttributes:disableAttrs forState:UIControlStateDisabled];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (self.viewControllers.count) {
viewController.hidesBottomBarWhenPushed = YES;
viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_back" higlightedImage:@"navigationbar_back_highlighted" target:self action:@selector(back)];
if (self.viewControllers.count <= 1) {
viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_more" higlightedImage:@"navigationbar_more_highlighted" target:self action:@selector(more)];
}
}
[super pushViewController:viewController animated:animated];
}
/**
* 返回
*/
- (void)back
{
[self popViewControllerAnimated:YES];
}
/**
* 更多
*/
- (void)more
{
[self popToRootViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = ZZGlobalBg;
if (iOS7) {
// 重新拥有滑动出栈的功能
self.interactivePopGestureRecognizer.delegate = nil;
}
}
@end