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;
 

  

上一篇:【微服务目录】.NET Core 微服务介绍


下一篇:uC/OS-II信号(OS_sem)块