I'm customizing the UIButton
programmatically here:
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setSelected:YES];
button.frame = CGRectMake(x, y, width, height);
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
[button setTitle:@"Button Title" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"buttonActive.png"] forState:UIControlStateSelected];
[button setBackgroundImage:[UIImage imageNamed:@"buttonActive.png"] forState:UIControlStateHighlighted];
[button setBackgroundImage:[UIImage imageNamed:@"buttonActive.png"] forState:UIControlStateDisabled];
The issue is if I'm holding down the image background image disappears until I'm releasing it...
I think you're in overkill mode :). Try setting button.png for UIControlStateNormal and buttonActive.png for UIControlStateHighlighted. No need for the rest. See if this works.
EDIT:
Also, remember: Image file names are case sensitive
Are you testing on device? Image names are case sensitive for device builds, but not for the simulator. For example, if your actual image file is named buttonactive.png, but you're calling it as buttonActive.png from your code, it will show up on the simulator, but not on the device.
Please ensure that the case for both image names matches the name of the actual file.
EDIT #2:
Try this code
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setSelected:YES];
button.frame = CGRectMake(x, y, width, height);
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
[button setTitle:@"Button Title" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"buttonActive.png"] forState:UIControlStateHighlighted];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With