0

在我的导航栏中,我有两个右键栏项目。一个是自定义按钮,另一个使用信息灯按钮类型。两者都工作得很好,但我想让自定义按钮具有默认发光,就像你触摸它时信息按钮一样。这可能吗?

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

1 回答 1

3

您只需要再添加一行代码,例如:-

customButton.showsTouchWhenHighlighted = TRUE;

在此之后您的代码输出如下: -

在此处输入图像描述

于 2013-08-02T20:57:23.137 回答