2
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];
4

4 回答 4

6

使用以下代码:

UITapGestureRecognizer* tapRecon = [[UITapGestureRecognizer alloc]
              initWithTarget:self action:@selector(navigationBarTap:)];
    tapRecon.numberOfTapsRequired = 1;
    [navController.navigationBar addGestureRecognizer:tapRecon];
于 2013-03-06T11:23:41.517 回答
4

你需要设置

bigLabel.userInteractionEnabled = YES;

因为默认情况下 UILabel 实例 userInteractionEnabled 是 NO

于 2013-03-06T11:33:10.840 回答
0

尝试为它设置一个框架,如下所示:

UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,32,32)];
[iv setBackgroundColor:[UIColor whiteColor]];
self.navigationItem.titleView = iv;
于 2013-03-06T11:24:02.017 回答
0
 UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]
                                            initWithTarget:self
                                            action:@selector(hideKeyBoard)];

    tapGesture.cancelsTouchesInView = NO;
    [self.navigationController.view addGestureRecognizer:tapGesture];


-(void)hideKeyBoard
{
    [self.view endEditing:YES];
}
于 2016-09-05T05:35:26.160 回答