IOS导航栏的使用方法 分类: ios开发 2015-01-29 10:40 282人阅读 评论(0) 收藏

  1. UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];  
  2.     //创建一个导航栏集合  
  3.     UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:nil];  
  4.     //在这个集合Item中添加标题,按钮  
  5.     //style:设置按钮的风格,一共有三种选择  
  6.     //action:@selector:设置按钮的点击事件  
  7.     //创建一个左边按钮  
  8.     UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"左边" style:UIBarButtonItemStyleBordered target:self action:@selector(clickLeftButton)];  
  9.     //创建一个右边按钮  
  10.     UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"右边" style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];  
  11.       
  12.     //设置导航栏的内容  
  13.     [navItem setTitle:@"图灵工作室"];  
  14.       
  15.     //把导航栏集合添加到导航栏中,设置动画关闭  
  16.     [navBar pushNavigationItem:navItem animated:NO];  
  17.       
  18.     //把左右两个按钮添加到导航栏集合中去  
  19.     [navItem setLeftBarButtonItem:leftButton];  
  20.     [navItem setRightBarButtonItem:rightButton];  
  21.       
  22.     //将标题栏中的内容全部添加到主视图当中  
  23.     [self.view addSubview:navBar]; 





  1. -(void)showDialog:(NSString *)str  
  2. {  
  3.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"这是一个对话框" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];  
  4.     [alert show];  
  5.     
  6. }  
  7.   
  8. -(void) clickLeftButton  
  9. {  
  10.     [self showDialog:@"点击了导航栏左边按钮"];  
  11. }  
  12.   
  13. -(void) clickRightButton  
  14. {  
  15.     [self showDialog:@"点击了导航栏右边按钮"];  
  16. }  

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-01-29 10:40  欣哥传奇  阅读(123)  评论(0编辑  收藏  举报