|
//
// FollowHeaderCell.m
// ThePaperBase
//
// Created by Huixin on 15/9/6.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "followHeaderCell.h"
@interface followHeaderCell() {
CGFloat titleWidth;
}
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UIImageView *expandImageView;
@property(nonatomic, strong)UILabel *markLabel;
@property(nonatomic, strong)UIView *lineView;
@end
@implementation followHeaderCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode) name:REFRESHAFTERNIGHTMODE object:nil];
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.titleLabel];
[self.backView addSubview:self.expandImageView];
[self.backView addSubview:self.markLabel];
[self.backView addSubview:self.lineView];
[self layoutViews];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)needrefreshNightMode {
[self layoutSubviews]; //bug5058: 夜间模式实时切换
}
- (void)layoutSubviews {
[super layoutSubviews];
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
_backView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
_titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
- (void)layoutViews {
if (self.isEditing) {
[self sendSubviewToBack:self.contentView];
}
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
}];
[self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(10);
make.centerY.equalTo(self.backView.centerY);
make.width.mas_equalTo(@0);
make.height.mas_equalTo(@18);
}];
[self.expandImageView makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView.left).offset(rect_screen.size.width-10);
make.centerY.equalTo(self.titleLabel.centerY);
make.width.mas_equalTo(@13);
make.height.mas_equalTo(@7.5);
}];
[self.markLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel.right).offset(5);
make.centerY.equalTo(self.titleLabel.centerY);
make.width.and.height.mas_equalTo(@15);
}];
[self.lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.bottom.equalTo(self.backView.bottom);
make.height.mas_equalTo(@1);
}];
}
- (UIView*)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
_backView.clipsToBounds = YES;
}
return _backView;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_titleLabel.textAlignment = NSTextAlignmentLeft;
_titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_titleLabel.backgroundColor = [UIColor clearColor];
}
_titleLabel.font = appFont(TEXT_THREE_LEVELSIZE, NO);
return _titleLabel;
}
- (UIImageView*)expandImageView {
if (!_expandImageView) {
_expandImageView = [[UIImageView alloc] init];
}
return _expandImageView;
}
- (UILabel*)markLabel {
if (!_markLabel) {
_markLabel = [[UILabel alloc] init];
_markLabel.backgroundColor = [UIColor colorWithHexString:@"0xc32128"];
_markLabel.layer.cornerRadius = 15/2;
_markLabel.clipsToBounds = YES;
_markLabel.textAlignment = NSTextAlignmentCenter;
_markLabel.textColor = [UIColor whiteColor];
_markLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
_markLabel.hidden = YES;
}
return _markLabel;
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (void)setTrackerBO:(trackerInfoBO*)data {
_trackerBO = data;
self.titleLabel.text = data.tags;
titleWidth = [self.titleLabel sizeThatFits:CGSizeMake(0, 18)].width;
[self.titleLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(10);
make.centerY.equalTo(self.backView.centerY);
make.width.mas_equalTo(titleWidth);
make.height.mas_equalTo(@18);
}];
if ([data.isOpen intValue] == 1) {
self.expandImageView.image = Image(@"follow/trackExpanded.png");
}else {
self.expandImageView.image = Image(@"follow/trackExpand.png");
}
if ([data.unNum intValue] > 0) {
self.markLabel.hidden = NO;
self.markLabel.text = data.unNum;
}else {
self.markLabel.hidden = YES;
}
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|