|
//
// myAttentionCell.m
// ThePaperHD
//
// Created by liyuan on 15/4/23.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "myAttentionCell.h"
#import "userBO.h"
@interface myAttentionCell(){
CGFloat titleHeight;
CGFloat labelWidth;
CGFloat timeWidth;
}
@property(nonatomic,strong)UIView *backView;
@property(nonatomic,strong)UILabel *auth;
@property(nonatomic,strong)UILabel *title;
@property(nonatomic,strong)UILabel *statu;
@property(nonatomic,strong)UILabel *time;
@property(nonatomic, strong)UIImageView *timeIcon;
@property(nonatomic,strong)UIView *line;
@property(nonatomic, strong)UILabel *markLabel;
//@property(nonatomic, strong)UIView *selectView;
@end
@implementation myAttentionCell
@synthesize indexPath = _indexPath;
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.clipsToBounds = YES;
self.backgroundColor =[UIColor colorWithHexString:CELLBACKCOLOR];
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.auth];
[self.backView addSubview:self.title];
[self.backView addSubview:self.statu];
[self.backView addSubview:self.timeIcon];
[self.backView addSubview:self.time];
[self.backView addSubview:self.line];
[self.contentView addSubview:self.markLabel];
}
return self;
}
//- (UIView *)selectView {
// if (!_selectView) {
// _selectView = [[UIView alloc]initWithFrame:CGRectZero];
// _selectView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
// }
// return _selectView;
//}
-(void) setTopicInfo:(TopicInfoBO *)topInfo{
userBO *user = setJsonDicToDataModel(topInfo.userInfo, [userBO class]);
self.auth.text = [NSString stringWithFormat:@"%@:",user.sname];
self.title.text = topInfo.title;
self.time.text = topInfo.publishTime;
self.statu.text = [self statuName:topInfo];
NSString *newNum = topInfo.unNums;
if ([newNum intValue] >0 ) {
self.markLabel.hidden = NO;
self.markLabel.text = newNum;
}else {
self.markLabel.hidden = YES;
self.markLabel.text = @"0";
}
timeWidth = widthForString(self.time.text, self.time.font, 12, NSLineBreakByWordWrapping);
titleHeight = [self.title sizeThatFits:CGSizeMake(rect_screen.size.width - 40, 0)].height;
[self relayout];
}
//状态:0- 已提交待审核;1- 进行中;2- 审核不通过;3- 关闭
-(NSString *)statuName:(TopicInfoBO *)topic{
NSString *str;
if ([topic.status integerValue] ==0) {
str = @"待审核";
self.time.hidden = NO;
}else if ([topic.status integerValue] ==1) {
if ([topic.replyedNum integerValue] <=0) {//【需求】话题:增加提问征集中的状态(bug:4323)
str = @"提问征集中";
}else{
str = @"进行中...";
}
self.time.hidden = NO;
}else if ([topic.status integerValue] ==2) {
str = @"未通过";
self.time.hidden = NO;
}else if ([topic.status integerValue] ==3) {
str = @"已关闭提问";
self.time.hidden = NO;
}
return str;
}
-(void)setIndexPath:(NSIndexPath *)index{
_indexPath = index;
}
#pragma mark - view
-(UIView *)backView{
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
_backView.clipsToBounds = YES;
}
return _backView;
}
-(UILabel *)auth{
if (!_auth) {
_auth = [[UILabel alloc] init];
_auth.textColor = [UIColor colorWithHexString:BLUECOLOR];
_auth.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_auth.backgroundColor = [UIColor clearColor];
}
return _auth;
}
-(UILabel *)title{
if (!_title) {
_title = [[UILabel alloc] init];
_title.textColor = [UIColor colorWithHexString:TextBlack];
_title.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
_title.lineBreakMode = NSLineBreakByWordWrapping;
_title.numberOfLines = 0;
_title.backgroundColor = [UIColor clearColor];
}
return _title;
}
-(UILabel *)statu{
if (!_statu) {
_statu = [[UILabel alloc]init];
_statu.textColor = [UIColor colorWithHexString:TextGray];
_statu.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
_statu.backgroundColor = [UIColor clearColor];
}
return _statu;
}
-(UIImageView *)timeIcon{
if (!_timeIcon) {
_timeIcon = [UIImageView new];
_timeIcon.image = Image(@"topic/timeImg.png");
}
return _timeIcon;
}
-(UILabel *)time{
if (!_time) {
_time = [[UILabel alloc]init];
_time.textAlignment = NSTextAlignmentRight;
_time.textColor = [UIColor colorWithHexString:TextGray];
_time.lineBreakMode = NSLineBreakByWordWrapping;
_time.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
_time.backgroundColor = [UIColor clearColor];
}
return _time;
}
- (UILabel*)markLabel {
if (!_markLabel) {
_markLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_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 *)line{
if (!_line) {
_line = [UIView new];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
-(void)layoutSubviews{
if (self.isEditing) {
[self sendSubviewToBack:self.contentView];
}
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.right.equalTo(self.contentView.right).offset(-10);
make.top.equalTo(self.contentView.top).offset(10);
make.bottom.equalTo(self.contentView.bottom);
}];
[self.markLabel makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView.right).offset(15/2);
make.width.equalTo(@15);
make.top.equalTo(self.backView.top).offset(-15/2);
make.height.equalTo(@15);
}];
[self.auth makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(10);
make.right.equalTo(self.backView.right).offset(-10);
make.top.equalTo(self.backView.top).offset(10);
make.height.equalTo(@10);
}];
// [self.title makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(self.auth.left);
// make.right.equalTo(self.backView.right).offset(-10);
// make.top.equalTo(self.auth.bottom).offset(5);
// make.height.mas_equalTo(25);
// }];
[self.statu makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.auth.left);
make.width.equalTo(@150);
make.top.equalTo(self.title.bottom).offset(10);
make.height.equalTo(@12);
}];
// [self.time makeConstraints:^(MASConstraintMaker *make) {
// make.right.equalTo(self.backView.right).offset(-10);
// make.width.mas_equalTo(@0);
// make.top.equalTo(self.statu.top);
// make.height.equalTo(@12);
// }];
[self.timeIcon makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.time.left).offset(-5);
make.width.equalTo(@10);
make.top.equalTo(self.statu.top).offset(1);
make.height.equalTo(@10);
}];
[self.line makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.top.equalTo(self.backView.bottom).offset(-1);
make.bottom.equalTo(self.backView.bottom);
}];
[super layoutSubviews];
}
-(void) relayout{
[self.title remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.auth.left);
// make.right.equalTo(self.backView.right).offset(-10);
make.width.equalTo(rect_screen.size.width-40);
make.top.equalTo(self.auth.bottom).offset(10);
make.height.mas_equalTo(titleHeight);
}];
[self.time remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView.right).offset(-10);
make.width.mas_equalTo(timeWidth);
make.top.equalTo(self.statu.top);
make.height.equalTo(@12);
}];
}
@end
|