有关导航栏的那些事

1、设置导航栏中间的标题:

self.title=@"popover";

2、设置导航栏的 标题 文字颜色:

[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

3、设置NavigationBar背景颜色

[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];

4、设置UIBarButtonSystemItem 的图标 的颜色:

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(clickPopoverButton:)];
    barButtonItem.tintColor=[UIColor whiteColor];   //改变UIBarButtonSystemItem的显示颜色
    self.navigationItem.rightBarButtonItem = barButtonItem;

5、设置导航栏标题的 字体颜色、文字阴影、文字大小:

NSShadow *navTitleShadow = [[NSShadow alloc]init];
    navTitleShadow.shadowColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
    navTitleShadow.shadowOffset = CGSizeMake(0, 5);
    
    [self.navigationController.navigationBar setTitleTextAttributes:
  @{NSForegroundColorAttributeName:[UIColor greenColor],/*[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0]*/
    NSShadowAttributeName:navTitleShadow,
    NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0]
    }];

6、使用图片作为导航栏标题。设置了 titleView 后,标题自动会隐藏:

self.title=@"popover";
self.navigationItem.titleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"qrcode_screen"]];

7、添加多个栏按钮项目:

UIBarButtonItem *shareItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(clickPopoverButton:)];
    UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(clickPopoverButton:)];
    self.navigationItem.rightBarButtonItems = @[shareItem,cameraItem];  //从右往左

8、自定义后退按钮的文字和颜色(这代码写在push前的控制器里才有效):

UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = backItem;

9、改变 “返回”图标和文字 的颜色
只有执行了下面代码,“返回”图标和文字才会变色,所以是放在执行push前,所有 UIBarButtonSystemItem 的都会变设置的颜色:

self.navigationController.navigationBar.tintColor=[UIColor whiteColor];

10、有导航栏时,获取是在第几页:

self.title = [NSString stringWithFormat:@"第%lu页",(unsigned long)self.navigationController.viewControllers.count];

11、将返回按钮的文字position设置不在屏幕上显示

[[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];

12、设置左边按钮和back按钮同时存在:

//在push进去的控制器里设置
self.navigationItem.leftItemsSupplementBackButton = YES;

//13、设置 titleView 的背景颜色:

self.navigationItem.titleView.backgroundColor=[UIColor redColor];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,267评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,925评论 25 709
  • 无论你多牛,都别忘形 现在好多富人、高官碰到下属、普通员工,都会表现得和颜悦色。 员工级别越低,他们越表现得亲切和...
    咕森阅读 317评论 0 0
  • 1:对事不对人。 在与学生沟通的时候,最好不要说一件事情就去翻旧账,逼学生去承认自己品德有问题。针对他犯的具体事情...
    天行健1101阅读 425评论 0 5
  • 每天坚持给孩子读一个故事,今天是阳光明媚的一天,午饭过后和朋友约好自驾一起向高椅岭驶去。两个孩子在车上特...
    婷婷沫阅读 375评论 0 0