|
//
// liveContTitleCell.m
// ThePaperHD
//
// Created by scar1900 on 15/3/11.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "liveContTitleCell.h"
#define CONTENTWIDTH 1060/2
@interface liveContTitleCell() {
CGFloat titleHeight;
}
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *timeLabel;
@property(nonatomic, strong)UIImageView *timePoint;
@property(nonatomic, strong)UIView *lineView;
@end
@implementation liveContTitleCell
@synthesize dataDic = _dataDic;
@synthesize isFirst;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.timeLabel];
[self.contentView addSubview:self.lineView];
[self.contentView addSubview:self.timePoint];
self.isFirst = YES;
}
return self;
}
- (void)setDataDic:(NSDictionary *)dic {
_dataDic = dic;
NSString *title = dic[@"title"];
self.titleLabel.text = title;
NSString *type = dic[@"type"];
if ([type isEqualToString:@"topTitle"]) {
self.timeLabel.hidden = YES;
self.timePoint.hidden = YES;
self.lineView.hidden = YES;
}else {
self.timeLabel.hidden = NO;
NSString *timeStr = dic[@"date"];
self.timeLabel.text =timeStr;
self.lineView.hidden = NO;
self.timePoint.hidden = NO;
}
titleHeight = [self.titleLabel sizeThatFits:CGSizeMake(CONTENTWIDTH, CGFLOAT_MAX)].height;
[self layoutSubviews];
[self.titleLabel setNeedsDisplay];
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textAlignment = NSTextAlignmentLeft;
_titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
_titleLabel.numberOfLines = 0;
}
_titleLabel.font = appFont(liveTitleFonteSize, NO);
return _titleLabel;
}
- (UILabel*)timeLabel {
if (!_timeLabel) {
_timeLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_timeLabel.backgroundColor = [UIColor clearColor];
_timeLabel.textAlignment = NSTextAlignmentLeft;
_timeLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_timeLabel.font = appFont(18, NO);
}
return _timeLabel;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc]initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (UIImageView*)timePoint {
if (!_timePoint) {
_timePoint = [[UIImageView alloc]initWithImage:Image(@"other/timePoint.png")];
}
return _timePoint;
}
- (void)layoutSubviews {
CGFloat padding = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
padding = 125;
}
// self.titleLabel.frame = CGRectMake(padding + 226/2, 20, CONTENTWIDTH, titleHeight);
[self.titleLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(padding+226/2);
make.width.mas_equalTo(CONTENTWIDTH);
make.top.equalTo(self.contentView.top).offset(20);
// make.bottom.equalTo(self.contentView.bottom).offset(-24);
make.height.mas_equalTo(titleHeight);
}];
// self.timeLabel.frame = CGRectMake(23+padding, 20, 50, 22);
[self.timeLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(23+padding);
make.width.mas_equalTo(50);
make.top.equalTo(self.contentView.top).offset(20);
make.height.mas_equalTo(22);
}];
// self.timePoint.frame = CGRectMake(padding, 23, 14, 14);
[self.timePoint remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(padding);
make.width.mas_equalTo(14);
make.centerY.equalTo(self.timeLabel.centerY);
make.height.mas_equalTo(14);
}];
CGFloat pointY = 0;
if (self.isFirst) {
pointY = self.timePoint.center.y;
}
// self.lineView.frame = CGRectMake(padding+7, pointY, 1, CGRectGetHeight(self.bounds));
[self.lineView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(padding+7);
make.width.mas_equalTo(1);
make.top.equalTo(self.contentView.top).offset(pointY);
make.bottom.equalTo(self.contentView.bottom);
}];
[super layoutSubviews];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|