Reputation: 7921
i would like to know if is possible to change the color of the glow appears when the showsTouchOnHighlighted option is enabled on a UIButton. Thanks
Upvotes: 1
Views: 9609
Reputation: 14128
According to me we can't change color of button. But you can change its image. You can set image for all the button states available.
- (void)setImage:(UIImage *)image forState:(UIControlState)state
Here you can find more details about the same: UIButton Class Reference
Choose your state as UIControlStateNormal, UIControlStateSelected or UIControlStateHighlighted as per your requirement.
Upvotes: 4
Reputation: 658
A image can be create with a UIColor so we need to add something like that:
[button setBackgroundImage:[self imageWithColor:[UIColor lightGrayColor]]
forState:UIControlStateHighlighted];
-
- (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Upvotes: 1