ios-新浪微博(5)设置导航栏主题

88 篇文章 0 订阅
#import "QHNavigationController.h"


@interface QHNavigationController ()

@end

@implementation QHNavigationController

//设置导航栏的主题 用了下面的一种新方法 :
+(void)initialize
{
    
    //[UINavigationBar appearance];
    
    //设置整个项目所有item 的主题样式
    //key:NS****AttributeName
     UIBarButtonItem *item = [UIBarButtonItem appearance];
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    //
    NSMutableDictionary *disableTextAttrs =[NSMutableDictionary dictionary];
    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0];
    disableTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
    
    //每个像素都有自己的颜色, 每种颜色都可以由RGB 色组成
    // 12bit 颜色 #ff #0f0 #00f #ff0
    //24bit 颜色 #ff0000 #ffff00 #000000 #ffffff
    
    //RGBA
    //32bit颜色 #556677
    //#ff00f
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**继承UINavigationController 
 //拦截 基本上都是通过自定义类 重写系统的方法来实现拦截
 
  *  重写这个方法的目的 能够拦截所有push 进来的控制器
 *
 *  @return viewController 即将push 进来的控制器
 */
//自定义UINavigationController
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //这里需要进行判断
    //比较特殊的控制器有可能不需要 
    //如果重写必须调用父类的push 方法
    
    if (self.viewControllers.count > 0) {//这时push进来的控制器ViewController 不是第一个子控制器
        //    //设置图片
        
        /*自动显示和隐藏tabbar*/
     
        viewController.hidesBottomBarWhenPushed = YES;
        /*设置导航栏上面的内容*/
        
        /*
             UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
             [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
             [backBtn setBackgroundImage:[UIImage imageNamed:@"navigationbar_back"] forState:UIControlStateNormal];
             [backBtn setBackgroundImage:[UIImage imageNamed:@"navigationbar_back_highlighted"] forState:UIControlStateHighlighted];
             //设置尺寸
             backBtn.size = backBtn.currentBackgroundImage.size;
             //这时一个自定义的方法
        
             viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
        */
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self Action:@selector(back) image:@"navigationbar_back" highImage:@"navigationbar_back_highlighted"];
        
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self Action:@selector(more) image:@"navigationbar_more" highImage:@"navigationbar_more_highlighted"];
        /*
             UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
             [moreBtn addTarget:self action:@selector(more) forControlEvents:UIControlEventTouchUpInside];
             [moreBtn setBackgroundImage:[UIImage imageNamed:@"navigationbar_more"] forState:UIControlStateNormal];
             [moreBtn setBackgroundImage:[UIImage imageNamed:@"navigationbar_more_highlighted"] forState:UIControlStateHighlighted];
             moreBtn.size = moreBtn.currentBackgroundImage.size;
        
             viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:moreBtn];
        */

    }
      [super pushViewController:viewController animated:YES];
    
   // NSLog(@"%lu %@",(unsigned long)self.viewControllers.count,viewController);
    
   
}


 -(void)back
 {
#warning 这里的self 不是self.navigationController
     //self 本来就是个导航控制器 self.navigationController 本来就是空的
 [self popViewControllerAnimated:YES];
//[self.navigationController] 是空的
     //注意这里的写法!!!
 }
 
 -(void)more
 {
 [self popToRootViewControllerAnimated:YES];
 }
 
/*
#pragma mark - Navigation                                                                                  

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值