2017-03-08 42 views
0

有什麼方法可以使導航欄標題可點擊嗎?我沒有任何特定的導航欄。我控制ViewController中的所有內容。如果有辦法,我很想知道。我一直在尋找它相當白,但找不到合適的答案。在導航欄使導航欄標題可點擊目標C iOS 10.2

回答

0

製作按鈕

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button addTarget:self 
      action:@selector(btnclick:) 
forControlEvents:UIControlEventTouchUpInside]; 
[button setTitle:@"Title" forState:UIControlStateNormal]; 
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
button.frame = CGRectMake(0, 0, self.view.frame.size.width, 64.0); 

self.navigationItem.titleView =button; 

-(void)btnclick:(id)sender 
{ NSLog(@"button click"); 
} 
0

你可以嘗試這樣的方式

的UIView *冠捷= [[UIView的頁頭] initWithFrame:方法CGRectZero]。 UIButton * button = [[UIButton alloc] initWithFrame:CGRectZero];};}};

[button addTarget:self action:@selector(buttonAction :) forControlEvents:UIControlEventTouchUpInside];

[button setTitle:@「Title here」forState:UIControlStateNormal];

[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

[button sizeToFit];

[topView addSubview:button];

[topView sizeToFit];

self.navigationItem.titleView = topView;

- (無效)buttonAction:(Id)的發送者 {

的NSLog(@ 「按鈕被點擊」);

}