澎湃iPad上线版本

askContentCell.m 7.8KB

    // // askContentCell.m // ThePaperHD // // Created by scar1900 on 15/1/27. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "askContentCell.h" @interface askContentCell() @end @implementation askContentCell @synthesize commentBO = _commentBO; @synthesize askNameHeight,askContentHeight; @synthesize isGrayBack = _isGrayBack; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor colorWithHexString:CardBackGroundColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.headPicImgView]; [self.contentView addSubview:self.vipImg]; [self.contentView addSubview:self.askNameLabel]; [self.contentView addSubview:self.askNameButton]; [self.contentView addSubview:self.answerNumLabel]; [self.contentView addSubview:self.askContentLabel]; [self.contentView addSubview:self.dashedLineView]; [self.contentView addSubview:self.pushInfo]; self.isGrayBack = NO; } return self; } - (void)setIsGrayBack:(BOOL)isGray { _isGrayBack = isGray; if (!isGray) { self.backgroundColor = [UIColor clearColor]; self.dashedLineView.hidden = NO; }else { self.dashedLineView.hidden = YES; self.backgroundColor = [UIColor colorWithHexString:CardBackGroundColor]; } } - (void)setCommentBO:(commentObjectVO *)data { _commentBO = 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]:@""; askNameHeight = heightForString(nameStr, self.askNameLabel.font, 500, self.askNameLabel.lineBreakMode); NSString *answerNumStr = data.answerNums?[NSString stringWithFormat:@"(%@个回答)",data.answerNums]:@""; askContentHeight = returnTextHeightWithRTLabel(data.content, 1170/2, appFont(interactionFontSize, NO),10); dispatch_async(dispatch_get_main_queue(), ^{ if ([user.isAuth integerValue] ==1) {//认证用户提问或回答,头像不显示加”V“(bug:4116) self.vipImg.hidden = NO; }else{ self.vipImg.hidden = YES; } self.headPicImgView.imageUrl = user.pic; self.askNameLabel.text = nameStr; self.answerNumLabel.text = answerNumStr; self.askContentLabel.text = data.content; [self layoutSubviews]; }); }); } - (AsyncImageView*)headPicImgView { if (!_headPicImgView) { _headPicImgView = [[AsyncImageView alloc]initWithFrame:CGRectZero]; _headPicImgView.layer.cornerRadius = 35.f/2; _headPicImgView.clipsToBounds = YES; _headPicImgView.isHaveWaterPrint = NO; _headPicImgView.defaultImage = Image(@"setting/loginIcon_s.png"); } return _headPicImgView; } -(UIImageView *)vipImg{//认证用户提问或回答,头像不显示加”V“(bug:4116) if (!_vipImg) { _vipImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; _vipImg.image = Image(@"setting/vipIcon.png"); _vipImg.hidden = YES; } return _vipImg; } - (UILabel*)askNameLabel { if (!_askNameLabel) { _askNameLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _askNameLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; _askNameLabel.font = appFont(15, NO); _askNameLabel.backgroundColor = [UIColor clearColor]; _askNameLabel.textAlignment = NSTextAlignmentLeft; } return _askNameLabel; } -(UIButton *)askNameButton{ if (!_askNameButton) { _askNameButton = [UIButton buttonWithType:UIButtonTypeCustom]; _askNameButton.backgroundColor = [UIColor clearColor]; [_askNameButton addTarget:self action:@selector(pushInfoSelector:) forControlEvents:UIControlEventTouchUpInside]; } return _askNameButton; } - (UILabel*)answerNumLabel { if (!_answerNumLabel) { _answerNumLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _answerNumLabel.font = appFont(11, NO); _answerNumLabel.backgroundColor = [UIColor clearColor]; _answerNumLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _answerNumLabel.textAlignment = NSTextAlignmentRight; } return _answerNumLabel; } - (UILabel*)askContentLabel { if (!_askContentLabel) { _askContentLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _askContentLabel.textColor = [UIColor colorWithHexString:TextBlack]; _askContentLabel.lineBreakMode = NSLineBreakByWordWrapping; _askContentLabel.numberOfLines = 0; _askContentLabel.font = appFont(interactionFontSize, NO); } return _askContentLabel; } - (UIImageView*)dashedLineView { if (!_dashedLineView) { _dashedLineView = [[UIImageView alloc]initWithFrame:CGRectZero]; _dashedLineView.image = Image(@"detailPage/dashedLine.png"); } return _dashedLineView; } -(UIButton *)pushInfo{ if (!_pushInfo) { _pushInfo = [UIButton buttonWithType:UIButtonTypeCustom]; _pushInfo.backgroundColor = [UIColor clearColor]; [_pushInfo addTarget:self action:@selector(pushInfoSelector:) forControlEvents:UIControlEventTouchUpInside]; } return _pushInfo; } -(void) pushInfoSelector:(UIButton *)btn{ if ([self.askContentDelegate respondsToSelector:@selector(gotoUserInfo:)]) { [self.askContentDelegate gotoUserInfo:self.commentBO]; } } - (void)layoutSubviews { [super layoutSubviews]; CGFloat padding = 0; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { padding = 125; } self.headPicImgView.frame = CGRectMake(20+padding, 25, 35, 35); self.vipImg.center = CGPointMake(self.headPicImgView.center.x+15, self.headPicImgView.center.y+12);//认证用户提问或回答,头像不显示加”V“(bug:4116) self.askNameLabel.frame = CGRectMake(CGRectGetMaxX(self.headPicImgView.frame)+18, CGRectGetMinY(self.headPicImgView.frame)+7, 500, askNameHeight); CGFloat nameWidth = widthForString(self.askNameLabel.text, self.askNameLabel.font, askNameHeight, self.askNameLabel.lineBreakMode); self.askNameButton.frame = CGRectMake(CGRectGetMinX(self.askNameLabel.frame)-5, 25, nameWidth+10, askNameHeight+10); self.askContentLabel.frame = CGRectMake(CGRectGetMinX(self.askNameLabel.frame), CGRectGetMaxY(self.headPicImgView.frame), 1170/2, askContentHeight); self.answerNumLabel.frame = CGRectMake(CGRectGetMaxX(self.askContentLabel.frame)-70, CGRectGetMinY(self.askNameLabel.frame), 70, CGRectGetHeight(self.askNameLabel.frame)); self.dashedLineView.frame = CGRectMake(CGRectGetMinX(self.askNameLabel.frame), CGRectGetHeight(self.bounds)-1, 1175/2, 1); self.pushInfo.frame = self.headPicImgView.frame; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end