Programmatically Disable Highlight on Click of UIButton

ios, objective-c, uibutton

Solution

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

Problem

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]; ``` None of these work.

Original source