zoukankan      html  css  js  c++  java
  • NavigationController的使用整理

    1.设置NavigationBar的背景色:

      self.navigationController.navigationBar.barTintColor = [UIColor redColor];

    2.设置NavigationBar上的标题

      self.navigationItem.title = @"Test";

    3.设置NavigationBar上标题的字体大小和颜色(使用富文本)

      self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor yellowColor],NSForegroundColorAttributeName,[UIFont     systemFontOfSize:50],NSFontAttributeName, nil];

    4.设置NavigationBar背景图:

       [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"1"] forBarMetrics:UIBarMetricsDefault];

    5.隐藏/显示返回键

      在需要隐藏返回键的界面设置:

        self.navigationItem.hidesBackButton = NO;

    6.保留返回箭头,去除返回标题或者改成其他标题

      在push进来的上一级界面中设置:

        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];

        backItem.title = @"";(不要标题就设置空字符串,其他标题直接写字符串就好了)

        self.navigationItem.backBarButtonItem = backItem;

    7.修改返回键以及标题颜色

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

    8.自定义rightButton

      方法一:
              UIBarButtonItem *button= [[UIBarButtonItem alloc] initWithImage:nil style:UIBarButtonItemStyleDone target:self action:@selector(action:)];
              self.navigation.rightBarButtonItem = button;
     
      方法二:
              UIButton *button =[ [UIButton alloc] initWithFrame:CGRectMake(0,0,30,30)];
              [button setImage:[UIImage imageNamed:@“”] forState:UIControlStateNormal];
              [button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
              UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:button];
              self.navigationItem.rightBarButtonItem = rightItem;
     

      

     

  • 相关阅读:
    优秀 Java 程序员写代码的风格
    最新!Apache Struts 又爆安全漏洞(危害程度特别大)
    Spring bean初始化及销毁你必须要掌握的回调方法
    Shiro Realm 权限的验证流程和缓存机制
    国人开源了一款小而全的 Java 工具类库,厉害啊!!
    Spring 解决循环依赖的 3 种方式!
    图解高内聚与低耦合,傻瓜都能看懂!
    五分钟搞懂 Linux 重点知识,傻瓜都能学会!
    微信扫码登录是如何实现的?
    shell实现group by聚合操作统计
  • 原文地址:https://www.cnblogs.com/small-octopus/p/4869568.html
Copyright © 2011-2022 走看看