iOS自定义UIButton

来源:互联网 发布:c语言产生0 1随机数 编辑:程序博客网 时间:2024/05/22 01:48

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


0 0