Skip to content

Instantly share code, notes, and snippets.

@jnjosh
Last active December 11, 2015 00:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnjosh/d20337095c696330460e to your computer and use it in GitHub Desktop.
Save jnjosh/d20337095c696330460e to your computer and use it in GitHub Desktop.
#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
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment