// // letterCell.m // ThePaperHD // // Created by liyuan on 15/7/15. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "letterCell.h" #import "AsyncImageView.h" #import "SDWebImageManager.h" #import "UIImage+wiRoundedRectImage.h" @interface letterCell(){ CGFloat titleHeight; } @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UIImageView *headImg; @property(nonatomic, strong)UIImageView *vImg; @property(nonatomic, strong)UILabel *nameLabel; @property(nonatomic, strong)UIImageView *timeIcon; @property(nonatomic, strong)UILabel *timeLabel; @property(nonatomic, strong)RTLabel *topicLabel; @property(nonatomic, strong)UILabel *InfoLabel; @property(nonatomic, strong)UIView *line; @property(nonatomic, strong)UIImageView *iconBack; @end @implementation letterCell @synthesize letterBo = _letterBo; - (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.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.backView]; [self.backView addSubview:self.headImg]; [self.backView addSubview:self.iconBack]; [self.backView addSubview:self.vImg]; [self.backView addSubview:self.nameLabel]; [self.backView addSubview:self.timeIcon]; [self.backView addSubview:self.timeLabel]; [self.backView addSubview:self.topicLabel]; [self.backView addSubview:self.InfoLabel]; [self.backView addSubview:self.line]; [self layoutSubviews]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.nameLabel.textColor = [UIColor colorWithHexString:TextBlack]; self.timeLabel.textColor = [UIColor colorWithHexString:TextLightGray]; self.topicLabel.textColor = [UIColor colorWithHexString:TextBlack]; [self.topicLabel setNeedsDisplay]; self.line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; //个人主页(我的提问,关注的问题,私信等):个人主页(我的提问,关注的问题,私信等)进入原新闻切换成夜间模式返回,显示异常(bug:6153) self.iconBack.image = [TPUserDefault instance].isNightMode.intValue >0 ? Image(@"detailPage/icon_night.png") :Image(@"detailPage/icon_sun.png"); } #pragma mark -- view -(UIView *)backView{ if (!_backView) { _backView = [UIView new]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } -(UIImageView *)headImg{ if (!_headImg) { _headImg = [[UIImageView alloc] initWithFrame:CGRectZero]; _headImg.userInteractionEnabled = YES; // UIBezierPath* path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(14, 14) radius:14 startAngle:0 endAngle:2*M_PI clockwise:YES]; // CAShapeLayer* shape = [CAShapeLayer layer]; // shape.path = path.CGPath; // _headImg.layer.mask = shape; } return _headImg; } - (UIImageView *)iconBack { if (!_iconBack) { _iconBack = [[UIImageView alloc] initWithFrame:CGRectZero]; _iconBack.image = [TPUserDefault instance].isNightMode.intValue >0 ? Image(@"detailPage/icon_night.png") :Image(@"detailPage/icon_sun.png"); } return _iconBack; } -(UIImageView *)vImg{ if (!_vImg) { _vImg = [[UIImageView alloc] initWithFrame:CGRectZero]; _vImg.image = Image(@"detailPage/verifyIcon.png"); _vImg.hidden = YES; } return _vImg; } -(UILabel *)nameLabel{ if (!_nameLabel) { _nameLabel = [UILabel new]; _nameLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _nameLabel.textColor = [UIColor colorWithHexString:TextBlack]; _nameLabel.backgroundColor = [UIColor clearColor]; } return _nameLabel; } -(UIImageView *)timeIcon{ if (!_timeIcon) { _timeIcon = [[UIImageView alloc] initWithFrame:CGRectZero]; _timeIcon.image = Image(@"topic/timeImg.png"); } return _timeIcon; } -(UILabel *)timeLabel{ if (!_timeLabel) { _timeLabel = [UILabel new]; _timeLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _timeLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _timeLabel.backgroundColor = [UIColor clearColor]; } return _timeLabel; } -(RTLabel *)topicLabel{ if (!_topicLabel) { _topicLabel = [RTLabel new]; _topicLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _topicLabel.textColor = [UIColor colorWithHexString:TextBlack]; _topicLabel.backgroundColor = [UIColor clearColor]; // _topicLabel.lineBreakMode = NSLineBreakByWordWrapping; // _topicLabel.numberOfLines = 0; _topicLabel.lineBreakMode = RTTextLineBreakModeWordWrapping; _topicLabel.lineSpacing = 7; } return _topicLabel; } -(UILabel *)InfoLabel{ if (!_InfoLabel) { _InfoLabel = [UILabel new]; _InfoLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; _InfoLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _InfoLabel.backgroundColor = [UIColor clearColor]; _InfoLabel.text = @"查看详情 >"; _InfoLabel.textAlignment = NSTextAlignmentRight; } return _InfoLabel; } -(UIView *)line{ if (!_line) { _line = [[UIView alloc] initWithFrame:CGRectZero]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _line; } #pragma mark -- setData -(void)setLetterBo:(letterBO *)bo{ _letterBo = bo; userBO *user = setJsonDicToDataModel(bo.userInfo, [userBO class]); if (isBlankString(user.pic)) { self.headImg.image = Image(@"login/loginIcon_s.png"); }else { if ([[TPUserDefault instance].readModeStr intValue] == imageMode) { [self updateUserHeadImage:user]; }else if ([[TPUserDefault instance].readModeStr intValue] == textMode) { self.headImg.image = Image(@"login/loginIcon_s.png"); }else { if ([Remote IsEnableWIFI]) { [self updateUserHeadImage:user]; }else { self.headImg.image = Image(@"login/loginIcon_s.png"); } } } // self.headImg.image = user.pic; if ([user.isAuth integerValue] ==1) { self.vImg.hidden = NO; }else{ self.vImg.hidden = YES; } if(!isBlankString(user.sname)){ self.nameLabel.text = [NSString stringWithFormat:@"%@:",user.sname]; }else{ self.nameLabel.text = @""; } self.timeLabel.text = bo.pubTime; self.topicLabel.text = bo.title; [self relayout]; } - (void)updateUserHeadImage:(userBO*)user{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ SDWebImageManager *imageManager = [SDWebImageManager sharedManager]; [imageManager downloadImageWithURL:[NSURL URLWithString:user.pic] options:SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) { } completed:^(UIImage *img, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { // UIImage *roundImage = [UIImage circleImage:img withParam:28]; dispatch_async(dispatch_get_main_queue(), ^{ self.headImg.image = img; }); }]; }); } -(void)layoutSubviews{ [self.backView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.left).offset(10); make.right.equalTo(self.right).offset(-10); make.top.equalTo(self.top).offset(10); make.bottom.equalTo(self.bottom); }]; [self.headImg makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@10); make.width.equalTo(@30); make.top.equalTo(self.backView.top).offset(10); make.height.equalTo(@30); }]; [self.iconBack makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.headImg); }]; [self.vImg makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headImg.right).offset(-10); make.width.equalTo(@10); make.top.equalTo(self.headImg.bottom).offset(-10); make.height.equalTo(@10); }]; [self.nameLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headImg.right).offset(10); make.right.equalTo(self.backView.right); make.top.equalTo(self.headImg.top); make.height.equalTo(@15); }]; // self.nameLabel.backgroundColor = RandomColor; [self.timeIcon makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.nameLabel.left); make.width.equalTo(@10); make.top.equalTo(self.nameLabel.bottom).offset(5); make.height.equalTo(@10); }]; [self.timeLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.timeIcon.right).offset(10); make.width.equalTo(@150); make.top.equalTo(self.timeIcon.top); make.height.equalTo(@10); }]; // [self.topicLabel makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.headImg.left); // make.right.equalTo(self.backView.right).offset(-10); // make.top.equalTo(self.headImg.bottom).offset(10); // make.height.mas_equalTo(30); // }]; [self.InfoLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.right).offset(-72); make.width.equalTo(@57); make.top.equalTo(self.backView.bottom).offset(-20); 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.height.equalTo(@1); }]; } -(void) relayout{ // titleHeight = [self.topicLabel sizeThatFits:CGSizeMake(rect_screen.size.width-40, 0)].height; titleHeight = returnTextHeightWithRTLabel(self.topicLabel.text, rect_screen.size.width-40, self.topicLabel.font, 7); [self.topicLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headImg.left); make.right.equalTo(self.backView.right).offset(-10); make.top.equalTo(self.headImg.bottom).offset(10); make.height.equalTo(titleHeight); }]; } @end