|
//
// categoryView.m
// ThePaperHD
//
// Created by liyuan on 15/7/2.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "categoryView.h"
@implementation categoryView
@synthesize cateBo = _cateBo;
@synthesize isSelect = _isSelect;
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.chineseName];
[self addSubview:self.ename];
[self addSubview:self.clickBtn];
}
return self;
}
#pragma mark -- view
-(UILabel *)chineseName{
if (!_chineseName) {
_chineseName = [[UILabel alloc] initWithFrame:CGRectZero];
_chineseName.font = appFont(17, NO);
_chineseName.textColor = [UIColor colorWithHexString:TextBlack];
_chineseName.backgroundColor = [UIColor clearColor];
_chineseName.textAlignment = NSTextAlignmentCenter;
}
return _chineseName;
}
-(UILabel *)ename{
if (!_ename) {
_ename = [[UILabel alloc]initWithFrame:CGRectZero];
_ename.font = appFont(7, NO);
_ename.textColor = [UIColor colorWithHexString:TextGray];
_ename.backgroundColor = [UIColor clearColor];
_ename.textAlignment = NSTextAlignmentCenter;
}
return _ename;
}
//-(UIView *)line{
// if (!_line) {
// _line = [[UIView alloc] init];
// _line.backgroundColor = [UIColor clearColor];
// }
// return _line;
//}
-(UIButton *)clickBtn{
if (!_clickBtn) {
_clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_clickBtn.backgroundColor = [UIColor clearColor];
[_clickBtn addTarget:self action:@selector(clickHandler:) forControlEvents:UIControlEventTouchUpInside];
}
return _clickBtn;
}
#pragma mark -- handler
-(void) clickHandler:(UIButton *)btn{
if ([self.cateDelegate respondsToSelector:@selector(changeTextColor:)]) {
[self.cateDelegate changeTextColor:_cateBo];
}
}
#pragma mark -- data
-(void)setCateBo:(categoryBO *)bo{
_cateBo = bo;
self.chineseName.text = _cateBo.name;
self.ename.text = _cateBo.enname;
// if ([_cateBo.name isEqualToString:@"精选"]) {
// self.chineseName.textColor = [UIColor colorWithHexString:BLUECOLOR];
// self.chineseName.font = appFont(20, NO);
// self.ename.textColor = [UIColor colorWithHexString:BLUECOLOR];
// }else{
// self.chineseName.textColor = [UIColor colorWithHexString:TextBlack];
// self.chineseName.font = appFont(17, NO);
// self.ename.textColor = [UIColor colorWithHexString:TextGray];
// }
}
-(void)setIsSelect:(BOOL)select{
_isSelect = select;
if (_isSelect) {
self.chineseName.font = appFont(20, NO);
self.chineseName.textColor = [UIColor colorWithHexString:BLUECOLOR];
self.ename.textColor = [UIColor colorWithHexString:BLUECOLOR];
}else{
self.chineseName.font = appFont(17, NO);
self.chineseName.textColor = [UIColor colorWithHexString:TextBlack];
self.ename.textColor = [UIColor colorWithHexString:TextGray];
}
}
#pragma mark -- layout
-(void)layoutSubviews{
[self.chineseName makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left);
make.right.equalTo(self.right);
make.top.equalTo(self.top).offset(12);
make.height.equalTo(@22);
}];
[self.ename makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left);
make.right.equalTo(self.right);
make.top.equalTo(self.chineseName.bottom);
make.height.equalTo(@13);
}];
[self.clickBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left);
make.top.equalTo(self.top);
make.right.equalTo(self.right);
make.bottom.equalTo(self.bottom);
}];
[super layoutSubviews];
}
@end
|