|
//
// ReadDefaultCell.m
// ThePaperBase
//
// Created by zhousan on 15/8/17.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "ReadDefaultCell.h"
@interface ReadDefaultCell ()
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UILabel *firstLabel;
@property (nonatomic, strong) UILabel *secondLabel;
@property (nonatomic, strong) UIView *lineView;
@end
@implementation ReadDefaultCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self addSubview:self.backView];
UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds))];
selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectedBackgroundView = selectView;
[self.backView addSubview:self.firstLabel];
[self.backView addSubview:self.secondLabel];
[self.backView addSubview:self.lineView];
[self.backView addSubview:self.rightBtn];
[self subLayoutSubViews];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds))];
selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectedBackgroundView = selectView;
self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
self.firstLabel.font = appFont(TEXT_THREE_LEVELSIZE, NO);
self.secondLabel.textColor = [UIColor colorWithHexString:TextLightGray];
}
- (void)setFirstString:(NSString *)firstString {
if (_firstString != firstString) {
_firstString = firstString;
self.firstLabel.text = _firstString;
}
}
- (void)setSecondString:(NSString *)secondString {
if (_secondString != secondString) {
_secondString = secondString;
self.secondLabel.text = _secondString;
}
}
- (void)setSelect:(BOOL)select {
_select = select;
self.rightBtn.selected = select;
}
- (UILabel *)firstLabel {
if (!_firstLabel) {
_firstLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_firstLabel.font = appFont(TEXT_THREE_LEVELSIZE, NO);
_firstLabel.textColor = [UIColor colorWithHexString:TextGray];
_firstLabel.backgroundColor = [UIColor clearColor];
}
return _firstLabel;
}
- (UILabel *)secondLabel {
if (!_secondLabel) {
_secondLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_secondLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_secondLabel.textColor = [UIColor colorWithHexString:TextLightGray];
_secondLabel.backgroundColor = [UIColor clearColor];
}
return _secondLabel;
}
- (UIView*)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectZero];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (UIButton *)rightBtn {
if (!_rightBtn) {
_rightBtn = [[UIButton alloc] initWithFrame:CGRectZero];
[_rightBtn setImage:Image(@"setting/offlineDownload.png") forState:UIControlStateNormal];
[_rightBtn setImage:Image(@"setting/offlineDownload_s.png") forState:UIControlStateSelected];
_rightBtn.userInteractionEnabled = NO;
// [_rightBtn addTarget:self action:@selector(cleanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _rightBtn;
}
#pragma mark - layout
- (void)subLayoutSubViews {
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self);
make.right.equalTo(self);
make.top.equalTo(self);
make.bottom.equalTo(self);
}];
[self.firstLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backView.top).offset(10);
make.left.equalTo(self.backView).offset(10);
make.size.mas_equalTo(CGSizeMake(150, 16));
}];
[self.secondLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.firstLabel.bottom).offset(10);
make.left.equalTo(self.backView).offset(10);
make.size.mas_equalTo(CGSizeMake(150, 12));
}];
[self.rightBtn makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView).offset(-10);
make.centerY.equalTo(self.backView);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
[self.lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView).offset(10);
make.right.equalTo(self.backView);
make.bottom.equalTo(self.backView);
make.height.mas_equalTo(1);
}];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end
|