UINavigationBar Touch

前端 未结 9 1288
北恋
北恋 2020-12-23 17:53

I would like to fire an event on touch when a user taps the title of the navigation bar of one of my views.

I\'m at a bit of a loss on whether I can access the view

9条回答
  •  臣服心动
    2020-12-23 18:06

    One of the possible options: (Use UILabel)

    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething:)];
    UILabel * titleView = [UILabel new];
    titleView.text = @"Test";
    [titleView sizeToFit];
    titleView.userInteractionEnabled = YES;
    [titleView addGestureRecognizer:tapGesture];
    
    self.navigationItem.titleView = titleView;
    

提交回复
热议问题