新浪微博开发五(导航栏功能的实现)


//

//  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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值