您的位置:首页 > 移动开发 > IOS开发

4000 IOS开发   导航条…

2016-12-12 23:02 323 查看
前几天被这个问题搞得头昏,转不过来弯。突然想起可以定义两个按钮放在同一个位置。点击一次就添加另一个按钮.

- (void) handleBtn1: (id) sender {

 
  NSLog(@"现在是按钮2事件");

 
  UIButton
*btn = [UIButton
buttonWithType:UIButtonTypeCustom];

 
  [btn setTitle:@"按钮1"
forState:UIControlStateNormal];

 
  [btn addTarget:self action:@selector(handleBtn2:) forControlEvents:UIControlEventTouchUpInside];

 
  btn.frame
= CGRectMake(0, 0, 40, 20);

 
  self.navigationItem.rightBarButtonItem
= [[UIBarButtonItem
alloc]initWithCustomView:btn];

}

- (void) handleBtn2: (id) sender {

   NSLog(@"现在是按钮1事件");

 
  UIButton
*btn = [UIButton
buttonWithType:UIButtonTypeCustom];

 
  [btn setTitle:@"按钮2"
forState:UIControlStateNormal];

 
  [btn addTarget:self action:@selector(handleBtn1:) forControlEvents:UIControlEventTouchUpInside];

 
  btn.frame
= CGRectMake(0, 0, 40, 20);

  
 

 
  self.navigationItem.rightBarButtonItem
= [[UIBarButtonItem
alloc]initWithCustomView:btn];

}

- (void) viewDidLoad {

 
  UIButton
*btn = [UIButton
buttonWithType:UIButtonTypeCustom];

 
  [btn setTitle:@"淡出"
forState:UIControlStateNormal];

 
  [btn addTarget:self action:@selector(handleBtn1:) forControlEvents:UIControlEventTouchUpInside];

 
  btn.frame
= CGRectMake(0, 0, 40, 20);

 
  self.navigationItem.rightBarButtonItem
= [[UIBarButtonItem
alloc]initWithCustomView:btn];

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: