ios – 以编程方式禁用UIButton单击时的突出显示

前端之家收集整理的这篇文章主要介绍了ios – 以编程方式禁用UIButton单击时的突出显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
必须有办法做到这一点,但我找不到它.我有一个以编程方式创建的按钮:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(25,self.view.frame.size.height/4,200,350);
[button setTitle:@"InBox" forState:UIControlStateNormal];
[button addTarget:self action:@selector(popViewController:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

我想要的只是按钮在触摸时不以任何方式突出显示或改变外观.到目前为止,我在创建按钮时尝试了以下操作:

[button setBackgroundImage:[UIImage imageNamed:nil] forState:UIControlStateSelected | UIControlStateHighlighted];

[button setBackgroundImage:nil forState:UIControlStateSelected];

[button setAdjustsImageWhenHighlighted:NO];

button.showsTouchWhenHighlighted = NO;

然后在我尝试的按钮操作中:

[sender setHighlighted:!sender.isHighlighted];

[sender setSelected:!sender.isSelected];

这些都不起作用.

解决方法

使您的UIButton成为自定义按钮,然后将UIImage背景应用于它.按下时不会突出显示或更改
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

猜你在找的iOS相关文章