MyUIButton.h
#import <UIKit/UIKit.h>
@interface MyUIButton : UIButton
@property (nonatomic, assign) BOOL isPressed;
- (void)setIsPressed:(BOOL)isPressed;
@end
MyUIButton.m
#import "MyUIButton.h"
@implementation MyUIButton
- (instancetype)init
{
self = [super init];
if (self) {
}
return self;
}
- (void)setIsPressed:(BOOL)isPressed {
_isPressed = isPressed;
if (isPressed) {
[self setBackgroundColor:[UIColor grayColor]];
}
else {
[self setBackgroundColor:[UIColor whiteColor]];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end