热更新demo

topicListCell.m 12KB

    // // topicListCell.m // ThePaperBase // // Created by YoungLee on 15/9/22. // Copyright © 2015年 scar1900. All rights reserved. // #import "topicListCell.h" #import "SDWebImageManager.h" #import "UIImage+wiRoundedRectImage.h" @interface topicListCell(){ CGFloat contentHeight; CGFloat typeWidth; CGFloat praiseWidth; CGFloat statusWidth; CGFloat leftPadding; } @end @implementation topicListCell @synthesize topic = _topic; -(void)setTopic:(TopicInfoBO *)topicInfo{ _topic = topicInfo; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ typeWidth = widthForString(_topic.categoryName, self.type.font, 10, self.type.lineBreakMode); userBO *user = setJsonDicToDataModel(_topic.userInfo, [userBO class]); NSString *backImageID = getImageNameFromURL(_topic.pic); praiseWidth = widthForString(_topic.praiseTimes, self.praiseNum.font, 12, self.praiseNum.lineBreakMode); NSString *statusText = [self statuName:_topic]; statusWidth = widthForString(statusText, self.status.font, TEXT_SEVEN_LEVELSIZE + 2, self.status.lineBreakMode)+30; NSAttributedString *attributeStr = getLineSpaceAttributedString(_topic.title?_topic.title:@"", [iphoneLineSpaceAndParaSpace returnLevel5LineSpace], appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize],NO)); // contentHeight = heightForString(_topic.title, self.content.font, rect_screen.size.width-20-32, self.content.lineBreakMode); dispatch_async(dispatch_get_main_queue(), ^{ self.type.text = _topic.categoryName; // self.content.text = _topic.title; self.content.attributedText = attributeStr; //bug5714: 问吧分类:刚进入的时候,会显示不全 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 (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"); } } } if ([user.isAuth integerValue] == 0) { self.vImg.hidden = YES; }else{ self.vImg.hidden = NO; } self.userName.text = user.sname; if (isBlankString(_topic.cornerLabel)) { self.corLabel.text = _topic.cornerLabel; self.corImg.hidden = YES; self.corLabel.hidden = YES; }else{ self.corImg.hidden = NO; self.corLabel.hidden = NO; if ([_topic.cornerLabel intValue] ==1) { self.corLabel.text = @"置顶"; }else if([_topic.cornerLabel intValue] ==2){ self.corLabel.text = @"热门"; }else if([_topic.cornerLabel intValue] == 3){ self.corLabel.text = @"最新"; } } if ([topicInfo.isFirstCard intValue] == 1) { leftPadding = 0; }else { leftPadding = 10; } self.praiseNum.text = _topic.praiseTimes; self.status.text = [self statuName:_topic]; [self remakeSubviews]; }); }); } - (void)updateUserHeadImage:(userBO*)user{ 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) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ UIImage *roundImage = [UIImage circleImage:img withParam:28]; dispatch_async(dispatch_get_main_queue(), ^{ self.userImg.image = roundImage; // 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; // self.userImg.layer.mask = shape; }); }); }]; } -(void)setLayoutSubviews{ contentHeight = heightForAttributeStringWithLabel(self.content.attributedText, rect_screen.size.width-20-32, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)); //bug5714: 问吧分类:刚进入的时候,会显示不全 [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.tempView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left); make.right.equalTo(self.backView.right); make.top.equalTo(self.backView.top); make.bottom.equalTo(self.backView.bottom); }]; [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(10); }]; [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)); }]; /** * bug:5077 5079(新闻详情页,相关话题卡片用户头像要加白圈) */ [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 makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.userImg.right).offset(10); make.top.equalTo(self.backView.top).offset(24); make.width.mas_equalTo(rect_screen.size.width/2); make.height.mas_equalTo(17); }]; [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 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 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 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.backView addSubview:self.corImg]; [self.corImg addSubview:self.corLabel]; [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.corImg.left); make.right.equalTo(self.corImg.right); make.top.equalTo(self.corImg.top); make.bottom.equalTo(self.corImg.bottom); // make.left.equalTo(self.backView.right).offset(-50); // make.width.equalTo(@30); // make.top.equalTo(self.backView.bottom).offset(-28); // make.height.equalTo(@15); }]; } - (void)remakeSubviews { contentHeight = heightForAttributeStringWithLabel(self.content.attributedText, rect_screen.size.width-20-32, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)); //bug5714: 问吧分类:刚进入的时候,会显示不全 self.content.font = appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize],NO); // [self.backView remakeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.contentView.left).offset(leftPadding); // make.right.equalTo(self.contentView.right).offset(0-leftPadding); // make.top.equalTo(self.contentView.top).offset(5); // make.bottom.equalTo(self.contentView.bottom).offset(-5); // }]; [self.tempView remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left); make.right.equalTo(self.backView.right); make.top.equalTo(self.backView.top); make.bottom.equalTo(self.backView.bottom); }]; [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); }]; [self.corImg remakeConstraints:^(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); }]; } @end