UINavicationController基本应用

来源:互联网 发布:php微商城开源系统 编辑:程序博客网 时间:2024/05/12 09:42

UINavicationController 导航栏,顾名思义为视图与视图之间切换的桥梁,简单来说,就是用来控制视图之间的跳转


请看以下代码分析:

  1. // 设置navigationbar的半透明效果
  2.     self.navigationController.navigationBar.translucent = NO;
  3.     [self.navigationController.navigationBar setTranslucent:NO];
  4. // 设置navigationbar上显示的标题 
  5.     self.title = @"navigationcontroller"; 
  6. // 设置navigationbar的颜色
  7.     [self.navigationController.navigationBar setBarTintColor:[UIColor purpleColor]];  
  8. // 设置navigationbar左边按钮 
  9.     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:self action:Nil]; 
  10. // 设置navigationbar右边按钮  
  11.     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:Nil];
  12. // 也可以自定义navigationbar 左右的按钮
  13. 思路:新建按钮控件rightbtn,然后 initWith  rightbtn 得到UIBarButtonItem,最后赋值给rightBarButtonItem

  1. // 设置navigationbar上左右按钮字体颜色
  2.     [self.navigationController.navigationBar setTintColor:[UIColor blueColor]];


设置导航条里面分段效果

  1. // 设置navigation上的titleview 
  2.     NSArray *arr = [NSArray arrayWithObjects:@"左边",@"右边", nil nil];  
  3.     UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:arr];  
  4.     segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;
  5. //添加点击事件
  6.    [segmentedController addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
  7.     self.navigationItem.titleView = segment; 

UISegmentedControl  分段控制,这个分段可以分为两个视图来控制,添加点击事件,根据index判断哪个分段被点击,执行相应的操作。


  1. -(IBAction)segmentClick:(id)sender  
  2. {  
  3.     switch ([sender selectedSegmentIndex]) {  
  4.         case 0:  
  5.         {  
  6.             UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了左边" delegate:self  cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];  
  7.             [alter show];  
  8.   //执行相应的操作
  9.         }  
  10.         break;  
  11.     case 1:  
  12.         {  
  13.             UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了右边" delegate:self  cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];  
  14.             [alter show];  
  15. //执行相应的操作
  16.         }  
  17.         break;  
  18.           
  19.         default:  
  20.             break;  
  21.     }  
  22. }  


如何结合UITabbarController 一起使用,敬请期待



0 0
原创粉丝点击