iOS开发笔记之三十四——关于导航栏与状态栏的操作总结

开发中自己常用的关于导航栏的编辑设置,都是经过IOS 8下验证过的,汇总如下,便于开发中查阅。

1、隐藏默认的返回按钮导航栏:

 self.navigationItem.hidesBackButtonYES;


2、自定义默认返回导航标题:

- (void) setLeftNavigationItem
{
    UIBarButtonItem *returnItem = [[UIBarButtonItem alloc] init];
    returnItem.title = @"返回";
    self.navigationItem.backBarButtonItem = returnItem;
}


2、如何隐藏导航栏底部边缘线:

  [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
   self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

3、设置(左)右导航栏

    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] init];
    rightItem.customView = self.headNavigationImageView;
   //图片设置为圆形
    self.headNavigationImageView.frame = CGRectMake(15, 15, 40, 40);
    self.headNavigationImageView.layer.cornerRadius = 20;
    self.headNavigationImageView.clipsToBounds = YES;

    self.navigationItem.rightBarButtonItem = rightItem;

4、设置导航栏和状态栏的背景色:
 //设置状态栏的背景色
    UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, [UIScreen mainScreen].bounds.size.width, 20)];
    statusBarView.backgroundColor=[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0];
    [self.navigationController.navigationBar addSubview:statusBarView];
//设置导航栏的背景色
    [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];
 //设置导航栏和状态栏背景颜色(统一设置)
   [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];

5、在导航栏中设置自定义标题
 UILabel *wTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 0,[[UIScreen mainScreen] bounds].size.width - 160, _navigationheight)];
//    wTitleLabel.backgroundColor = [UIColor blackColor];
    wTitleLabel.font = [UIFont systemFontOfSize:22];
    wTitleLabel.textColor = [UIColor whiteColor];
    wTitleLabel.backgroundColor = [UIColor clearColor];
    wTitleLabel.textAlignment = NSTextAlignmentCenter;
    wTitleLabel.text = @"设置";
    self.navigationItem.titleView = wTitleLabel;
    self.navigationItem.titleView.frame = CGRectMake(15, 15, 40, 40);

6、手动设定rootVC

 DefaultViewController  *dVC = [[DefaultViewController  alloc] initWithNibName:@"DefaultViewController " bundle:nil];
    dVC.title = @" ";
    dVC.navigationController.navigationBarHidden = NO;
    UINavigationController * navigationCtr = [[UINavigationController alloc] initWithRootViewController:dVC];
    [[UIApplication sharedApplication].delegate window].rootViewController = navigationCtr; 

7、未完待续。
参考资料:




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值