// // toolBarBtnView.m // ThePaperHD // // Created by scar1900 on 15/3/10. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "toolBarBtnView.h" @implementation toolBarBtnView @synthesize edgeInsets = _edgeInsets; @synthesize titleText = _titleText; - (id)initWithFrame:(CGRect)frame withTarget:(id)target selector:(SEL)action buttonImage:(NSString*)imagePath hilightImage:(NSString*)hilightImagePath selectImage:(NSString*)selectImagePath{ self = [super initWithFrame:frame]; if (self) { [self addSubview:self.toolBtn]; [self addSubview:self.titleLabel]; [self.toolBtn setImage:Image(imagePath) forState:UIControlStateNormal]; [self.toolBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; if (hilightImagePath && !isBlankString(hilightImagePath)) { [self.toolBtn setImage:Image(hilightImagePath) forState:UIControlStateHighlighted]; } if (selectImagePath && !isBlankString(selectImagePath)) { [self.toolBtn setImage:Image(selectImagePath) forState:UIControlStateSelected]; } } return self; } - (UIButton*)toolBtn { if (!_toolBtn) { _toolBtn = [UIButton buttonWithType:UIButtonTypeCustom]; } return _toolBtn; } - (UILabel*)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textColor = [UIColor colorWithHexString:TextGray]; _titleLabel.font = appFont(11, NO); _titleLabel.textAlignment = NSTextAlignmentCenter; } return _titleLabel; } - (void)setEdgeInsets:(UIEdgeInsets)edgeInsets { [self.toolBtn setImageEdgeInsets:edgeInsets]; } - (void)setTitleText:(NSString *)text { _titleText = text; self.titleLabel.text = text; } - (void)layoutSubviews { self.toolBtn.frame = self.bounds; self.titleLabel.frame = CGRectMake(0, CGRectGetHeight(self.bounds)-10, CGRectGetWidth(self.bounds), 10); } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end