UINavigationController使用

    FirstViewController *firstVC=[[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:Nil];
    //实例化导航控制器
    UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:firstVC];
    
    //将包装好的导航控制器,作为rootviewcontroller
    self.window.rootViewController=navController;


以上是UINavigationController实例化


----------------------------------------------------------------------------------------------------------------------------------------------------------------------

使用UINavigationController推出下一个页面:

[self.navigationController pushViewController:secondVC animated:YES];

UINavigationController各种属性设置

    if (ISiOS7) {
        //在IOS7里,这个是设置导航条文字的颜色
        self.navigationController.navigationBar.tintColor=[UIColor redColor];
        //在IOS7里,这个是设置导航条背景的颜色
        self.navigationController.navigationBar.barTintColor=[UIColor blueColor];

    }else{
        //不是ios7,只能设置导航条的颜色
        self.navigationController.navigationBar.tintColor=[UIColor orangeColor];
    }
    //自定义标题
    UILabel *titleLable=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
    //ios6里,label默认背景是白色,但是ios7默认透明
    if (!ISiOS7) {
        titleLable.backgroundColor=[UIColor clearColor];
    }
    titleLable.text=self.title;
    titleLable.font=[UIFont boldSystemFontOfSize:20];
    titleLable.textColor=[UIColor whiteColor];
    self.navigationItem.titleView=titleLable;
    
    
    //自定义导航条按键(利用系统自带的样式)
    UIBarButtonItem *barButtonItem1=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(onBarButtonItemClicked:)];
    UIBarButtonItem *barButtonItem2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(onBarButtonItemClicked:)];
    
//    self.navigationItem.rightBarButtonItem=barButtonItem;//单独一个按键
    self.navigationItem.rightBarButtonItems=@[barButtonItem1,barButtonItem2];
    
    
    //自定义导航条按键,完全自定义
    UIButton *leftBarButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftBarButton setTitle:@"左侧按键" forState:UIControlStateNormal];
    [leftBarButton setTitle:@"左侧点击" forState:UIControlStateHighlighted];
    [leftBarButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [leftBarButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    leftBarButton.frame=CGRectMake(0, 0, 100, 44);
    [leftBarButton addTarget:self action:@selector(onLeftBarButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    //将上面自定义的按键,包装成一个导航条按键
    UIBarButtonItem *leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:leftBarButton];
    self.navigationItem.leftBarButtonItem=leftBarButtonItem;
    
    
    
    //设置导航条背景
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg"] forBarMetrics:UIBarMetricsDefault];
    



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值