在我的导航栏中,我有两个右键按钮栏项目。一个是自定义按钮,另一个是信息灯按钮类型。两者都很好用,但我想使自定义按钮具有默认发光,就像您触摸信息按钮时一样。这可能吗?
// Default info light btn
UIButton *infoBtn = [UIButton buttonWithType:UIButtonTypeInfoLight];
UIBarButtonItem *infoBtnItem = [[UIBarButtonItem alloc]initWithCustomView:infoBtn];
// Custom Btn
UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setFrame:CGRectMake(0, 0, btnImage.size.width, btnImage.size.height)];
[customButton setBackgroundImage:btnImage forState:UIControlStateNormal];
[customButton addTarget:self action:@selector(rightDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customButtonItem = [[UIBarButtonItem alloc] initWithCustomView:wlButton];
NSArray *rightBtns = @[customButtonItem, infoBtnItem];
[navItem setRightBarButtonItems:rightBtns animated:YES];
最佳答案
您只需要再添加一行代码,例如:
customButton.showsTouchWhenHighlighted = TRUE;
在此之后,您的代码输出类似以下内容: