|
//
// relateTopicCell.m
// ThePaperHD
//
// Created by scar1900 on 15/5/13.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "relateTopicCell.h"
#define tableWidht 1230/2
@interface relateTopicCell() {
CGFloat contentHeight;
CGFloat statusWidth;
}
@property(nonatomic, strong)UIView* backView;
@property(nonatomic, strong)UILabel *topicNameLabel;
@property(nonatomic, strong)UILabel *topicStatusLabel;
@property(nonatomic, strong)UIView *lineView;
@property(nonatomic, strong)UILabel *contentLabel;
@property(nonatomic, strong)UIView *selectView;
@end
@implementation relateTopicCell
@synthesize topicInfo = _topicInfo;
@synthesize padding;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleGray;
self.selectedBackgroundView = self.selectView;
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.topicNameLabel];
[self.backView addSubview:self.topicStatusLabel];
[self.backView addSubview:self.contentLabel];
[self.backView addSubview:self.lineView];
}
return self;
}
- (void)setTopicInfo:(TopicInfoBO *)data {
_topicInfo = data;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
userBO *user = setJsonDicToDataModel(data.userInfo, [userBO class]);
NSString *nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@"";
contentHeight = returnTextHeightWithRTLabel(data.title, tableWidht, appFont(18, NO), 10);
NSString *statusStr = @"";
if ([data.status intValue] == 0) {
statusStr = @"待审核";
}else if ([data.status intValue] == 1) {
statusStr = @"进行中...";
}else if ([data.status intValue] == 2) {
statusStr = @"审核不通过";
}else if ([data.status intValue] == 3) {
statusStr = @"已关闭提问";
}
statusWidth = widthForString(statusStr, appFont(14, NO), 18, NSLineBreakByWordWrapping);
dispatch_async(dispatch_get_main_queue(), ^{
self.topicNameLabel.text = nameStr;
self.contentLabel.text = data.title;
self.topicStatusLabel.text = statusStr;
[self layoutSubviews];
});
});
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectZero];
_backView.backgroundColor = [UIColor clearColor];
}
return _backView;
}
- (UIView *)selectView {
if (!_selectView) {
_selectView = [[UIView alloc]initWithFrame:CGRectZero];
_selectView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _selectView;
}
- (UILabel *)topicNameLabel {
if (!_topicNameLabel) {
_topicNameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_topicNameLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_topicNameLabel.font = appFont(14, NO);
_topicNameLabel.backgroundColor = [UIColor clearColor];
_topicNameLabel.textAlignment = NSTextAlignmentLeft;
}
return _topicNameLabel;
}
- (UILabel *)topicStatusLabel {
if (!_topicStatusLabel) {
_topicStatusLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_topicStatusLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_topicStatusLabel.font = appFont(14, NO);
_topicStatusLabel.backgroundColor = [UIColor clearColor];
_topicStatusLabel.textAlignment = NSTextAlignmentLeft;
}
return _topicStatusLabel;
}
- (UILabel*)contentLabel {
if (!_contentLabel) {
_contentLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_contentLabel.font = appFont(18, NO);
_contentLabel.textAlignment = NSTextAlignmentLeft;
_contentLabel.textColor = [UIColor colorWithHexString:TextBlack];
_contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
_contentLabel.numberOfLines = 0;
_contentLabel.backgroundColor = [UIColor clearColor];
}
return _contentLabel;
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc]initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.backView.frame = CGRectMake(padding, 0, tableWidht, CGRectGetHeight(self.contentView.bounds));
self.selectView.frame = self.backView.frame;
self.topicNameLabel.frame = CGRectMake(0, 25, 500, 18);
self.topicStatusLabel.frame = CGRectMake(CGRectGetWidth(self.backView.bounds)-statusWidth,
CGRectGetMinY(self.topicNameLabel.frame), statusWidth, 18);
self.contentLabel.frame = CGRectMake(0,
CGRectGetMaxY(self.topicNameLabel.frame)+12, tableWidht, contentHeight);
self.lineView.frame = CGRectMake(0, CGRectGetHeight(self.backView.bounds)-1, tableWidht, 1);
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|