|
//
// filterSelectBtn.m
// ThePaperHD
//
// Created by scar1900 on 15/4/27.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "filterSelectBtn.h"
@interface filterSelectBtn()
@property(nonatomic, strong)UIButton* selectBtn;
@property(nonatomic, strong)UILabel* assistLabel;
@property(nonatomic, strong)UIView *line;
@end
@implementation filterSelectBtn
@synthesize isHaveLine = _isHaveLine;
@synthesize category;
@synthesize delegate;
- (id)initWithFrame:(CGRect)frame
category:(categoryBO*)cate{
self = [super initWithFrame:frame];
if (self) {
self.category = cate;
[self addSubview:self.selectBtn];
[self.selectBtn setTitle:cate.name forState:UIControlStateNormal];
[self.selectBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.assistLabel];
self.assistLabel.text = cate.enname;
[self addSubview:self.line];
}
return self;
}
- (UIButton*)selectBtn {
if (!_selectBtn) {
_selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_selectBtn setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal];
[_selectBtn setTitleColor:[UIColor colorWithHexString:@"0xc57130"] forState:UIControlStateSelected];
_selectBtn.titleLabel.font = appFont(18, NO);
}
return _selectBtn;
}
- (UILabel*)assistLabel {
if (!_assistLabel) {
_assistLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_assistLabel.font = appFont(9, NO);
_assistLabel.textAlignment = NSTextAlignmentCenter;
_assistLabel.textColor = [UIColor colorWithHexString:TextBlack];
_assistLabel.backgroundColor = [UIColor clearColor];
}
return _assistLabel;
}
- (UIView*)line {
if (!_line) {
_line = [[UIView alloc]initWithFrame:CGRectZero];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
- (void)setIsHaveLine:(BOOL)isHave {
_isHaveLine = isHave;
if (!isHave) {
self.line.hidden = YES;
}else self.line.hidden = NO;
}
- (void)setBtnSelected:(BOOL)selected{
self.selectBtn.selected = selected;
if (selected) {
_assistLabel.textColor = [UIColor colorWithHexString:@"0xc57130"];
}else {
_assistLabel.textColor = [UIColor colorWithHexString:TextBlack];
}
}
- (void)btnClick:(UIButton*)btn {
if (btn.selected) {
return;
}
[self setBtnSelected:YES];
if ([self.delegate respondsToSelector:@selector(selectFilterBtn:)]) {
[self.delegate selectFilterBtn:self.category];
}
}
- (void)layoutSubviews {
[super layoutSubviews];
self.selectBtn.frame = self.bounds;
self.assistLabel.frame = CGRectMake(0,
CGRectGetHeight(self.bounds)-15,
CGRectGetWidth(self.bounds),
15);
self.line.frame = CGRectMake(0,
CGRectGetHeight(self.bounds)/2-15,
1,
30);
}
@end
|