Skip to content

@jnjosh /TWTButton.h secret
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#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
Something went wrong with that request. Please try again.