secret
Last active

  • Download Gist
TWTButton.h
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#import <UIKit/UIKit.h>
 
typedef void(^TWTButtonTapHandler)(void);
 
@interface TWTButton : UIButton
 
@property (nonatomic, copy) TWTButtonTapHandler tapHandler;
@property (nonatomic, strong) UIFont *titleFont UI_APPEARANCE_SELECTOR;
 
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (void)setTitleEdgeInsets:(UIEdgeInsets)titleEdgeInsets UI_APPEARANCE_SELECTOR;
 
@end
TWTButton.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#import "TWTButton.h"
 
@implementation TWTButton
 
#pragma mark - Properties
 
- (void)setTitleFont:(UIFont *)titleFont
{
if (_titleFont != titleFont) {
_titleFont = titleFont;
[self.titleLabel setFont:_titleFont];
}
}
 
#pragma mark - Override
 
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
{
[super setBackgroundImage:image forState:state];
}
 
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state
{
[super setTitleColor:color forState:state];
}
 
- (void)setTitleEdgeInsets:(UIEdgeInsets)titleEdgeInsets
{
[super setTitleEdgeInsets:titleEdgeInsets];
}
 
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state
{
[super setTitleShadowColor:color forState:state];
}
 
#pragma mark - Tap Support
 
- (void)setTapHandler:(TWTButtonTapHandler)tapHandler
{
_tapHandler = [tapHandler copy];
[self addTarget:self action:@selector(didTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
}
 
- (void)didTouchUpInside:(id)sender
{
if (self.tapHandler) {
self.tapHandler();
}
}
 
@end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.