如何防止 UIButton 在触摸时发生变化?
我有一个按钮,几乎需要整个 xib,这样如果原始视图的任何部分被触摸,我就可以在屏幕上推送另一个 viewController。我已经为这个按钮创建了一个 IBOutlet,它工作得很好,但是我不希望整个窗口在触摸时变成“蓝色”(类似于按下小按钮时)。我尝试了在类似的帖子中找到的以下两种方法: 如何防止 UIButton 在按下时突出显示?,但这两种方法都不起作用。我还需要设置什么吗?
- (void)viewDidLoad
{
[super viewDidLoad];
self.entireWindowButton.adjustsImageWhenHighlighted = NO;
[self.entireWindowButton setImage: [self.entireWindowButton imageForState:UIControlStateNormal] forState:UIControlStateHighlighted];
}
I have a button that pretty much takes an entire xib so that I can push another viewController on the screen if any part of the original view is touched. I've created an IBOutlet to this button and it works great, however I don't want the entire window to turn "blue" when it is touched (similar to when a small button is pressed). I've tried the following two methods that I found in a similar SO post: How can I prevent a UIButton from highlighting when pressed?, but neither method works. Is there something else I need to set up?
- (void)viewDidLoad
{
[super viewDidLoad];
self.entireWindowButton.adjustsImageWhenHighlighted = NO;
[self.entireWindowButton setImage: [self.entireWindowButton imageForState:UIControlStateNormal] forState:UIControlStateHighlighted];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到这是一个老问题,但如果您将 UIButtons 类型设置为自定义,那么“adjustsImageWhenHighlighted = NO”将起作用,并且默认情况下设置为“NO”。
I realise this is old question but if you set the UIButtons type to custom then "adjustsImageWhenHighlighted = NO" will work and it is set to NO by default.