Skip to content

Instantly share code, notes, and snippets.

@k06a
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k06a/8209263483155a756e1b to your computer and use it in GitHub Desktop.
Save k06a/8209263483155a756e1b to your computer and use it in GitHub Desktop.
#import <UIKit/UIKit.h>
@interface TintedButton : UIButton
@end
#import "TintedButton.h"
@implementation TintedButton
- (void)fix
{
for (NSNumber *state in @[@(UIControlStateNormal),
@(UIControlStateHighlighted),
@(UIControlStateSelected),
@(UIControlStateHighlighted|UIControlStateSelected),
@(UIControlStateDisabled)])
{
[self setImage:[self imageForState:state.unsignedIntegerValue] forState:state.unsignedIntegerValue];
[self setBackgroundImage:[self backgroundImageForState:state.unsignedIntegerValue] forState:state.unsignedIntegerValue];
}
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
[self fix];
}
return self;
}
- (void)setImage:(UIImage *)image forState:(UIControlState)state
{
[super setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:state];
}
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
{
[super setBackgroundImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:state];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment