热更新demo

reTopicCell.m 19KB

    // // reTopicCell.m // ThePaperHD // // Created by YoungLee on 15/6/9. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "reTopicCell.h" #import "UIImage+wiRoundedRectImage.h" #import "SDWebImageManager.h" @interface reTopicCell(){ CGFloat contentHeight; CGFloat typeWidth; CGFloat praiseWidth; CGFloat statusWidth; CGFloat contentPadding; CGFloat IMAGE_HEIGHT; NSString *backImageID; userBO *user; NSString *statusText; NSAttributedString *attributeStr; } @end @implementation reTopicCell @synthesize topic = _topic; - (void)awakeFromNib { // Initialization code } //54 6E A5 - (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) { if (IS_IPHONE_6P) { contentPadding = 15; }else if (IS_IPHONE_6) { contentPadding = 15; }else { contentPadding = 10; } IMAGE_HEIGHT = 225*(rect_screen.size.width-2*contentPadding)/300; self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:self.backView]; [self.backView addSubview:self.tempView]; [self.backView addSubview:self.type]; [self.backView addSubview:self.content]; [self.backView addSubview:self.baiquan]; [self.backView addSubview:self.userImg]; [self.backView addSubview:self.vImg]; [self.backView addSubview:self.userName]; [self.backView addSubview:self.praiseImg]; [self.backView addSubview:self.praiseNum]; [self.backView addSubview:self.status]; [self.backView addSubview:self.gotoInfo]; // [self.backView addSubview:self.corImg]; // [self.corImg addSubview:self.corLabel]; // self.corLabel.hidden = YES; [self setLayoutSubviews]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ [_gotoInfo setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } -(AsyncImageView *)backView{ if (!_backView) { _backView = [[AsyncImageView alloc] initWithFrame:CGRectZero]; _backView.isHaveWaterPrint = NO; _backView.backgroundColor = [UIColor whiteColor]; } return _backView; } -(UIView *)tempView{ if (!_tempView) { _tempView = [[UIImageView alloc] initWithFrame:CGRectZero]; _tempView.image = Image(@"detailPage/temp.png"); } return _tempView; } -(UILabel *)type{ if (!_type) { _type = [[UILabel alloc] initWithFrame:CGRectZero]; _type.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _type.textColor = [UIColor whiteColor]; _type.backgroundColor = [UIColor clearColor]; _type.textAlignment = NSTextAlignmentLeft; } return _type; } -(UILabel *)content{ if (!_content) { _content = [[UILabel alloc] initWithFrame:CGRectZero]; _content.textColor = [UIColor whiteColor]; _content.numberOfLines = 0; _content.backgroundColor = [UIColor clearColor]; _content.lineBreakMode = NSLineBreakByCharWrapping; _content.textAlignment = NSTextAlignmentJustified; } // _content.lineSpacing = HeadCardLineSpace; return _content; } -(UIImageView *)userImg{ if (!_userImg) { _userImg = [[UIImageView alloc] initWithFrame:CGRectZero]; _userImg.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; // _userImg.layer.mask = shape; } return _userImg; } -(UIImageView *)vImg{ if (!_vImg) { _vImg = [[UIImageView alloc] initWithFrame:CGRectZero]; _vImg.image = Image(@"detailPage/verifyIcon.png"); } return _vImg; } -(UILabel *)userName{ if (!_userName) { _userName = [[UILabel alloc] initWithFrame:CGRectZero]; _userName.textColor = [UIColor whiteColor]; _userName.textAlignment = NSTextAlignmentLeft; _userName.lineBreakMode = NSLineBreakByWordWrapping; _userName.numberOfLines = 0; } _userName.font = appFont(TEXT_SIX_LEVELSIZE, NO); return _userName; } -(UIImageView *)praiseImg{ if (!_praiseImg) { _praiseImg = [[UIImageView alloc]initWithFrame:CGRectZero]; _praiseImg.image = Image(@"detailPage/praiseIcon.png"); _praiseImg.userInteractionEnabled = YES; } return _praiseImg; } - (UIView *)baiquan { if (!_baiquan) { _baiquan = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; _baiquan.layer.cornerRadius = 15; _baiquan.layer.masksToBounds = YES; _baiquan.backgroundColor = [UIColor whiteColor]; } return _baiquan; } -(UILabel *)praiseNum{ if (!_praiseNum) { _praiseNum = [[UILabel alloc] initWithFrame:CGRectZero]; _praiseNum.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _praiseNum.textColor = [UIColor whiteColor]; _praiseNum.lineBreakMode = NSLineBreakByWordWrapping; } return _praiseNum; } -(UILabel *)status{ if (!_status) { _status = [[UILabel alloc] initWithFrame:CGRectZero]; _status.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _status.textColor = [UIColor whiteColor]; } return _status; } -(UIButton *)gotoInfo{ if (!_gotoInfo) { _gotoInfo = [UIButton buttonWithType:UIButtonTypeCustom]; _gotoInfo.frame = CGRectMake(0, 0, 50, 50); _gotoInfo.titleLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _gotoInfo.layer.masksToBounds = YES; _gotoInfo.layer.cornerRadius = 5; _gotoInfo.backgroundColor = [UIColor whiteColor]; _gotoInfo.userInteractionEnabled = NO; [_gotoInfo setTitle:@"查看话题详情" forState:UIControlStateNormal]; [_gotoInfo setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal]; } return _gotoInfo; } //-(UILabel *)corLabel{ // if (!_corLabel) { // _corLabel = [[UILabel alloc]initWithFrame:CGRectZero]; // _corLabel.textColor = [UIColor whiteColor]; // _corLabel.font = appFont(11, NO); // _corLabel.textAlignment = NSTextAlignmentCenter; // _corLabel.backgroundColor = [UIColor clearColor]; //// _corLabel.layer.borderColor = [UIColor whiteColor].CGColor; //// _corLabel.layer.cornerRadius = 3; //// _corLabel.layer.borderWidth = 1; // } // return _corLabel; //} // //-(UIImageView *)corImg{ // if (!_corImg) { // _corImg = [[UIImageView alloc] initWithFrame:CGRectZero]; // _corImg.image = Image(@"topic/topCorner.png"); // _corImg.hidden = YES; // } // return _corImg; //} -(void)setTopic:(TopicInfoBO *)topicInfo{ _topic = topicInfo; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ typeWidth = widthForString(_topic.categoryName, self.type.font, 10, self.type.lineBreakMode); user = setJsonDicToDataModel(_topic.userInfo, [userBO class]); backImageID = getImageNameFromURL(_topic.pic); praiseWidth = widthForString(_topic.praiseTimes, self.praiseNum.font, 12, self.praiseNum.lineBreakMode); statusText = [self statuName:_topic]; statusWidth = widthForString(statusText, self.status.font, TEXT_SEVEN_LEVELSIZE + 2, self.status.lineBreakMode)+30; // contentHeight = heightForString(_topic.title, self.content.font, rect_screen.size.width-20-32, self.content.lineBreakMode); // contentHeight = returnTextHeightWithRTLabel(_topic.title, rect_screen.size.width-20-32, self.content.font, HeadCardLineSpace); attributeStr = getLineSpaceAttributedString(_topic.title, [iphoneLineSpaceAndParaSpace returnLevel5LineSpace], appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize],NO)); if (isBlankString(user.pic)) { self.userImg.image = Image(@"login/loginIcon_s.png"); }else { if ([[TPUserDefault instance].readModeStr intValue] == imageMode) { [self updateUserHeadImage:user]; }else if ([[TPUserDefault instance].readModeStr intValue] == textMode) { self.userImg.image = Image(@"login/loginIcon_s.png"); }else { if ([Remote IsEnableWIFI]) { [self updateUserHeadImage:user]; }else { self.userImg.image = Image(@"login/loginIcon_s.png"); } } } NSInvocationOperation *operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(readyToReLayout) object:nil]; [[TPUserDefault instance].globalQueue addOperation:operation]; // dispatch_async(dispatch_get_main_queue(), ^{ // [self updateCellUI]; // }); }); } - (void)readyToReLayout { [self performSelectorOnMainThread:@selector(updateCellUI) withObject:nil waitUntilDone:YES]; // usleep(1); } - (void)updateCellUI { self.type.text = _topic.categoryName; self.content.attributedText = attributeStr; if ([[TPUserDefault instance].readModeStr intValue] == imageMode) { self.backView.imageView.hidden = NO; self.backView.imageUrl = _topic.pic; self.backView.imageId = backImageID; }else if ([[TPUserDefault instance].readModeStr intValue] == textMode) { self.backView.imageView.hidden = YES; }else { if ([Remote IsEnableWIFI]) { self.backView.imageView.hidden = NO; self.backView.imageUrl = _topic.pic; self.backView.imageId = backImageID; }else { self.backView.imageView.hidden = YES; } } if ([user.isAuth integerValue] == 0) { self.vImg.hidden = YES; }else{ self.vImg.hidden = NO; } self.userName.text = user.sname; self.praiseNum.text = _topic.praiseTimes; self.status.text = [self statuName:_topic]; [self remakeSubviews]; } - (void)updateUserHeadImage:(userBO*)userBO{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ SDWebImageManager *imageManager = [SDWebImageManager sharedManager]; [imageManager downloadImageWithURL:[NSURL URLWithString:userBO.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.userImg.image = roundImage; }); }]; }); } //状态:0- 已提交待审核;1- 进行中;2- 审核不通过;3- 关闭 -(NSString *)statuName:(TopicInfoBO *)topic{ NSString *str; if ([topic.status integerValue] ==0) { str = @"待审核"; }else if ([topic.status integerValue] ==1) { if ([topic.replyedNum integerValue] <=0) {//【需求】话题:增加提问征集中的状态(bug:4323) str = @"提问征集中"; }else{ str = @"进行中..."; } }else if ([topic.status integerValue] ==2) { str = @"未通过"; }else if ([topic.status integerValue] ==3) { str = @"已关闭提问"; } return str; } - (void)setLayoutSubviews { // self.backView.frame = CGRectMake(10, 0, rect_screen.size.width-20, IMAGE_HEIGHT); [self.backView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(contentPadding); make.top.equalTo(self.contentView.top); make.width.mas_equalTo(rect_screen.size.width-2*contentPadding); make.height.mas_equalTo(IMAGE_HEIGHT); }]; // self.type.frame = CGRectMake(CGRectGetWidth(self.backView.frame)/2 - 87/2, 18, 87, 35); [self.tempView makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.backView); }]; [self.type makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(16); make.top.equalTo(self.backView.bottom).offset(-25); make.width.mas_equalTo(typeWidth); make.height.mas_equalTo(12); }]; // self.userImg.frame = CGRectMake(16, CGRectGetHeight(self.backView.frame)-49, 30, 30); [self.userImg makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(16); make.top.equalTo(self.backView.top).offset(16); make.width.mas_equalTo(28); make.height.mas_equalTo(28); }]; [self.baiquan makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.userImg); make.centerY.equalTo(self.userImg); make.size.mas_equalTo(CGSizeMake(30, 30)); }]; // self.vImg.frame = CGRectMake(CGRectGetMaxX(self.userImg.frame)-10, CGRectGetMaxY(self.userImg.frame)-11, 11, 11); [self.vImg makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.userImg.right).offset(-10); make.top.equalTo(self.userImg.bottom).offset(-10); make.width.mas_equalTo(11); make.height.mas_equalTo(11); }]; // self.userName.frame = CGRectMake(CGRectGetMaxX(self.vImg.frame)+10, CGRectGetMinY(self.userImg.frame), widthForString(self.userName.text, self.userName.font, 30, self.userName.lineBreakMode), 30); [self.userName makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.userImg.right).offset(10); make.top.equalTo(self.backView.top).offset(24); make.width.mas_equalTo(250); make.height.mas_equalTo(17); }]; // self.praiseImg.frame = CGRectMake(CGRectGetMaxX(self.userName.frame)+10, CGRectGetMinY(self.userImg.frame)+19/2, 11, 11); [self.praiseImg makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.type.right).offset(10); make.top.equalTo(self.type.top).offset(-2); make.width.mas_equalTo(10); make.height.mas_equalTo(11); }]; // self.praiseNum.frame = CGRectMake(CGRectGetMaxX(self.praiseImg.frame)+5, CGRectGetMinY(self.userImg.frame), widthForString(self.praiseNum.text, self.praiseNum.font, 30, self.praiseNum.lineBreakMode), 30); [self.praiseNum makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.praiseImg.right).offset(5); make.top.equalTo(self.type.top); make.width.mas_equalTo(praiseWidth); make.height.mas_equalTo(11); }]; // self.status.frame= CGRectMake(CGRectGetMaxX(self.praiseNum.frame)+10, CGRectGetMinY(self.userImg.frame), widthForString(self.status.text, self.status.font, 30, self.status.lineBreakMode), 30); [self.status makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.praiseNum.right).offset(10); make.top.equalTo(self.type.top); make.width.mas_equalTo(statusWidth); make.height.mas_equalTo(11); }]; // self.content.frame = CGRectMake(CGRectGetMinX(self.userImg.frame),CGRectGetMinY(self.userImg.frame)-contentHeight-10, CGRectGetWidth(self.backView.frame)-100, contentHeight); [self.content makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.backView.bottom).offset(-(40+contentHeight)); make.left.equalTo(self.backView.left).offset(16); make.right.equalTo(self.backView.right).offset(-16); make.height.mas_equalTo(contentHeight); }]; [self.gotoInfo makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.backView.right).offset(-16); make.width.mas_equalTo(84); make.top.equalTo(self.backView.top).offset(16); make.height.mas_equalTo(28); }]; // [self.corImg makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.backView.right).offset(-86); // make.width.equalTo(@56); // make.top.equalTo(self.backView.bottom).offset(-42); // make.height.equalTo(@29); // }]; // // [self.corLabel makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.backView.right).offset(-50); // make.width.equalTo(@30); // make.top.equalTo(self.backView.bottom).offset(-28); // make.height.equalTo(@15); // }]; // self.gotoInfo.frame = CGRectMake(CGRectGetWidth(self.backView.frame)-100, CGRectGetMaxY(self.backView.frame)-45, 85, 30); } -(void)remakeSubviews{ contentHeight = heightForAttributeStringWithLabel(self.content.attributedText, rect_screen.size.width-2*contentPadding-32, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)); [self.type remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(16); make.top.equalTo(self.backView.bottom).offset(-25); make.width.mas_equalTo(typeWidth); make.height.mas_equalTo(10); }]; [self.praiseNum remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.praiseImg.right).offset(5); make.top.equalTo(self.type.top); make.width.mas_equalTo(praiseWidth); make.height.mas_equalTo(11); }]; [self.status remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.praiseNum.right).offset(10); make.top.equalTo(self.type.top); make.width.mas_equalTo(statusWidth); make.height.mas_equalTo(11); }]; [self.content remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.backView.bottom).offset(-(40+contentHeight)); make.left.equalTo(self.backView.left).offset(16); make.right.equalTo(self.backView.right).offset(-16); make.height.mas_equalTo(contentHeight); }]; } @end