bigLabel = [[UILabel alloc] init];
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
[tap setNumberOfTapsRequired:1];
[bigLabel addGestureRecognizer:tap];
bigLabel.backgroundColor=[UIColor clearColor];
bigLabel.text = _referenceObject.textForCell;
//bigLabel.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"Header1.png"]];
bigLabel.font = [UIFont fontWithName:@"HelveticaNeueLTStd-Bd" size: 21.0];
bigLabel.font =[UIFont boldSystemFontOfSize:21.0f];
bigLabel.textColor = [UIColor whiteColor];
[bigLabel sizeToFit];
[self.navigationItem setTitleView:bigLabel];
答案 0 :(得分:6)
使用以下代码:
UITapGestureRecognizer* tapRecon = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(navigationBarTap:)];
tapRecon.numberOfTapsRequired = 1;
[navController.navigationBar addGestureRecognizer:tapRecon];
答案 1 :(得分:4)
你需要设置
bigLabel.userInteractionEnabled = YES;
因为默认情况下UILabel实例userInteractionEnabled为NO
答案 2 :(得分:0)
尝试设置框架,如下所示:
UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,32,32)];
[iv setBackgroundColor:[UIColor whiteColor]];
self.navigationItem.titleView = iv;
答案 3 :(得分:0)
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(hideKeyBoard)];
tapGesture.cancelsTouchesInView = NO;
[self.navigationController.view addGestureRecognizer:tapGesture];
-(void)hideKeyBoard
{
[self.view endEditing:YES];
}