如何在此按钮上获取操作事件?
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.scrollView];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0, 0, 32, 32);
backButton.adjustsImageWhenHighlighted = YES;
[backButton setImage:backButtonImage forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_scrollView addSubview:backButton];
答案 0 :(得分:0)
你的代码很好。实现这个功能
- (void)backButtonAction:(id)sender
{
NSLog(@"backButton pressed");
}
如果没有调用,请检查scroolView的userInteractionEnabled并设置为YES
_scrollView.userInteractionEnabled = YES;