在我的导航栏中,我有两个右键按钮栏项。一个是自定义按钮,另一个是信息灯按钮类型。两者都运行良好,但我想使自定义按钮具有默认发光,与触摸时信息按钮的方式相同。这可能吗?
// 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];
答案 0 :(得分:3)
你只需要再添加一行代码,如: -
customButton.showsTouchWhenHighlighted = TRUE;
在此之后您的代码输出如下: -