• 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;
     

      

     

  • 相关阅读:
    Linux编程之UDP SOCKET全攻略
    Java8 flatMap的sample
    swagger bug
    bash中的pasue
    树、二叉树、满二叉树、完全二叉树概念分清
    复习一下高中数学
    SpringBoot Junit Maven JaCoCo
    事务传播和隔离
    springboot swagger2 泛型踩坑记
    Code::Blocks debug程序
  • 原文地址:https://www.cnblogs.com/small-octopus/p/4869568.html
Copyright © 2020-2023  润新知