// // otherPersonTopicCell.m // ThePaperBase // // Created by YoungLee on 15/9/1. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "otherPersonTopicCell.h" #import "commentOkButton.h" @interface otherPersonTopicCell(){ CGFloat contentHeight; } @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UIImageView *typeImg; @property(nonatomic, strong)UILabel *typeLabel; @property(nonatomic, strong)UILabel *nameLabel; @property(nonatomic, strong)UILabel *content; @property(nonatomic, strong)UIImageView *timeIcon; @property(nonatomic, strong)UILabel *time; @property(nonatomic, strong)commentOkButton *okBtn; @end @implementation otherPersonTopicCell @synthesize topic = _topic; @synthesize user = _user; - (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.okBtn changeButtonImage]; [self.contentView addSubview:self.backView]; [self.contentView addSubview:self.typeImg]; [self.typeImg addSubview:self.typeLabel]; [self.backView addSubview:self.nameLabel]; [self.backView addSubview:self.content]; [self.backView addSubview:self.timeIcon]; [self.backView addSubview:self.time]; [self.backView addSubview:self.okBtn]; } return self; } #pragma mark -- view -(UIView *)backView{ if (!_backView) { _backView = [[UIView alloc] init]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } -(UILabel *)nameLabel{ if (!_nameLabel) { _nameLabel = [UILabel new]; _nameLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _nameLabel.textColor = [UIColor colorWithHexString:TextBlack]; } return _nameLabel; } -(UIImageView *)typeImg{ if (!_typeImg) { _typeImg = [UIImageView new]; _typeImg.image = Image(@"topic/otherType.png"); } return _typeImg; } -(UILabel *)typeLabel{ if (!_typeLabel) { _typeLabel = [[UILabel alloc] init]; _typeLabel.backgroundColor = [UIColor clearColor]; _typeLabel.textColor = [UIColor whiteColor]; _typeLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _typeLabel.textAlignment = NSTextAlignmentCenter; _typeLabel.text = @"话"; } return _typeLabel; } -(UILabel *)content{ if (!_content) { _content = [[UILabel alloc] init]; _content.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _content.numberOfLines = 0; _content.lineBreakMode = NSLineBreakByWordWrapping; _content.textColor = [UIColor colorWithHexString:TextBlack]; _content.backgroundColor = [UIColor clearColor]; } return _content; } -(UIImageView *)timeIcon{ if (!_timeIcon) { _timeIcon = [[UIImageView alloc] initWithFrame:CGRectZero]; _timeIcon.image = Image(@"topic/timeImg.png"); } return _timeIcon; } -(UILabel *)time{ if (!_time) { _time = [[UILabel alloc]init]; _time.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _time.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _time.backgroundColor = [UIColor clearColor]; } return _time; } - (commentOkButton*)okBtn { if (!_okBtn) { _okBtn = [[commentOkButton alloc]initWithFrame:CGRectZero]; [_okBtn addTarget:self action:@selector(commentOK:) forControlEvents:UIControlEventTouchUpInside]; } return _okBtn; } - (void)commentOK:(UIButton*)btn { if (btn.selected) { return; } [self.okBtn setSelected:YES animated:YES]; NSDictionary *dic = @{@"topicId":_topic.topicId,@"otype":@3}; __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:2000 requestUrl:optTopicURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success) { NSString *praseNumStr = responseData[@"praiseTimes"]; if ([praseNumStr intValue] < 1000) {// 个人动态,对一个创建的话题点赞,超过千位数的,会显示…(bug:5187) Self.okBtn.text = praseNumStr; } // Self.okBtn.text = praseNumStr; Self.topic.isPraised = @"1"; Self.topic.praiseTimes = praseNumStr; TPLOG(@"点赞成功"); }else { TPLOG(@"点赞失败"); } }]; } -(void)setTopic:(TopicInfoBO *)topicBO{ _topic = topicBO; self.content.text = _topic.title; self.time.text = _topic.publishTime; self.okBtn.text = _topic.praiseTimes; contentHeight = [self.content sizeThatFits:CGSizeMake(rect_screen.size.width-40, 0)].height; [self relayout]; } -(void)setUser:(userBO *)userBO{ _user = userBO; self.nameLabel.text = [NSString stringWithFormat:@"%@:",_user.sname]; } -(void)layoutSubviews{ [super layoutSubviews]; [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.nameLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.right.equalTo(self.backView.right).offset(-20); make.top.equalTo(self.backView.top).offset(9); make.height.equalTo(@12); }]; [self.typeImg makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.backView.right).offset(5); make.width.equalTo(@25); make.top.equalTo(self.backView.top).offset(-5); make.height.equalTo(@25); }]; [self.typeLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.typeImg.left).offset(5); make.right.equalTo(self.typeImg.right); make.top.equalTo(self.typeImg.top); make.bottom.equalTo(self.typeImg.bottom).offset(-5); }]; [self.timeIcon makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.content.left); make.width.equalTo(@10); make.top.equalTo(self.content.bottom).offset(13); make.height.equalTo(@10); }]; [self.time makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.timeIcon.right).offset(5); make.right.equalTo(@200); make.top.equalTo(self.timeIcon.top); make.height.equalTo(@10); }]; [self.okBtn makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.right).offset(-50); make.width.equalTo(@50); make.top.equalTo(self.time.top).offset(-5); make.height.equalTo(@35); }]; } -(void) relayout{ [self.content remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).equalTo(10); make.right.equalTo(self.backView.right).equalTo(-10); make.top.equalTo(self.nameLabel.bottom).offset(9); make.height.mas_equalTo(contentHeight); }]; } @end