以编程方式禁用单击UIButton时的突出显示 [英] Programmatically Disable Highlight on Click of UIButton
本文介绍了以编程方式禁用单击UIButton时的突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
必须有办法做到这一点,但我找不到它。我有一个按编程方式创建的按钮:
There must be a way to do this, but I can't find it. I have a button I have created programmatically:
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];
我想要的只是按钮在触摸时不以任何方式突出显示或改变外观。到目前为止,我在创建按钮时尝试了以下操作:
All I want is for the button not to highlight or change in appearance in any way when it is touched. So far I have tried the following when creating the button:
[button setBackgroundImage:[UIImage imageNamed:nil] forState:UIControlStateSelected | UIControlStateHighlighted];
AND
[button setBackgroundImage:nil forState:UIControlStateSelected];
AND
[button setAdjustsImageWhenHighlighted:NO];
AND
button.showsTouchWhenHighlighted = NO;
然后在我尝试的按钮操作中:
Then in the button action I tried:
[sender setHighlighted:!sender.isHighlighted];
AND
[sender setSelected:!sender.isSelected];
这些都不起作用。
推荐答案
使您的UIButton成为自定义按钮,然后对其应用UIImage背景。按下时不会突出显示或更改
Make your UIButton a custom button and then apply a UIImage background to it. It won't highlight or change when pressed
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
这篇关于以编程方式禁用单击UIButton时的突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文