澎湃iPad上线版本

myCreateCell.m 12KB

    // // myCreateCell.m // ThePaperHD // // Created by YoungLee on 15/4/27. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "myCreateCell.h" @interface myCreateCell(){ CGFloat titleHeight; CGFloat errorHeight; NSString *status; CGFloat titleWidth; } @property(nonatomic,strong)UIView *backView; @property(nonatomic,strong)UILabel *title; @property(nonatomic,strong)UILabel *statu; @property(nonatomic, strong)UILabel *time; @property(nonatomic,strong)UIButton *editBtn; @property(nonatomic, strong)UIButton *editBtnBg; @property(nonatomic,strong)UIView *line; @property(nonatomic, strong)UIImageView *errorIcon; @property(nonatomic, strong)UILabel *errorText; @property(nonatomic, strong)UILabel *markLabel; @property(nonatomic, strong)UIButton *selectBtn; @end @implementation myCreateCell @synthesize topicInfo = _topicInfo; @synthesize indexPath = _indexPath; - (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 = UITableViewCellSelectionStyleGray; self.clipsToBounds = NO; self.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [self.contentView addSubview:self.backView]; [self.backView addSubview:self.selectBtn]; [self.backView addSubview:self.title]; [self.backView addSubview:self.statu]; [self.backView addSubview:self.time]; [self.backView addSubview:self.line]; [self.backView addSubview:self.errorIcon]; [self.backView addSubview:self.errorText]; [self.backView addSubview:self.markLabel]; [self.backView addSubview:self.editBtn]; [self.backView addSubview:self.editBtnBg]; } return self; } - (void)setTopicInfo:(TopicInfoBO *)topInfo { _topicInfo = topInfo; status = topInfo.status; //话题:我的关注话题列表中未读数及红点标志位置不统一,要求统一格式显示(bug:4288)将40改成25 titleWidth = widthForString(topInfo.title, appFont(18, NO), 25, NSLineBreakByWordWrapping); if(0 ==[topInfo.status integerValue] || 2==[topInfo.status integerValue]){ if (titleWidth <= gambitCenterPopSize.width - 67) { titleHeight = 25; }else{ titleWidth = gambitCenterPopSize.width - 67; titleHeight = heightForString(topInfo.title, appFont(18, NO), gambitCenterPopSize.width-67, NSLineBreakByWordWrapping); } }else { if (titleWidth <= gambitCenterPopSize.width - 30) { titleHeight = 25; }else{ titleWidth = gambitCenterPopSize.width-30; titleHeight = heightForString(topInfo.title, appFont(18, NO), gambitCenterPopSize.width-30, NSLineBreakByWordWrapping); } } self.title.text = topInfo.title; errorHeight = heightForString(topInfo.rejectReson, appFont(9, NO), gambitCenterPopSize.width-30, NSLineBreakByWordWrapping); self.time.text = topInfo.publishTime; self.statu.text = [self statuName:topInfo]; self.errorText.text = topInfo.rejectReson; if ([topInfo.status integerValue] == 0 || [topInfo.status integerValue] ==2) { [self.editBtn setTitle:@"删除" forState:UIControlStateNormal]; if([topInfo.interactionNum integerValue] > 0){ self.editBtnBg.hidden = YES; self.editBtn.hidden = YES; }else{ self.editBtnBg.hidden = NO; self.editBtn.hidden = NO; } }else{ [self.editBtn setTitle:@"编辑" forState:UIControlStateNormal]; self.editBtn.hidden = NO; self.editBtnBg.hidden = NO; } // if([topInfo.waitReplyNum integerValue] >0 &&[topInfo.replyedNum integerValue]>0){ // self.editBtnBg.hidden = YES; // self.editBtn.hidden = YES; // }else{ // self.editBtn.hidden = NO; // self.editBtnBg.hidden = NO; // } NSString *newNum = topInfo.unNums; if ([newNum intValue] >0 ) { self.markLabel.hidden = NO; self.markLabel.text = newNum; }else if ([newNum intValue] == 0){ self.markLabel.hidden = YES; self.markLabel.text = @"0"; }else { self.markLabel.hidden = NO; self.markLabel.text = @""; } } -(void)setIndexPath:(NSIndexPath *)index{ _indexPath = index; } //状态:0- 已提交待审核;1- 进行中;2- 审核不通过;3- 关闭 -(NSString *)statuName:(TopicInfoBO *)topic{ NSString *str; if ([topic.status integerValue] ==0) { str = @"待审核"; // self.time.hidden = YES; self.errorIcon.hidden = YES; }else if ([topic.status integerValue] ==1) { if ([topic.replyedNum integerValue] <=0) {//【需求】话题:增加提问征集中的状态(bug:4323) str = @"提问征集中"; }else{ str = @"进行中..."; } // self.time.hidden = NO; self.errorIcon.hidden = YES; }else if ([topic.status integerValue] ==2) { str = @"未通过"; // self.time.hidden = YES; self.errorIcon.hidden = NO; }else if ([topic.status integerValue] ==3) { str = @"已关闭提问"; // self.time.hidden = NO; self.errorIcon.hidden = YES; } return str; } #pragma mark - view -(UIView *)backView{ if (!_backView) { _backView = [[UIView alloc] init]; } return _backView; } -(UIButton *)selectBtn{ if (!_selectBtn) { _selectBtn = [[UIButton alloc] init]; [_selectBtn setBackgroundImage:[self createImageWithColor:[UIColor clearColor]] forState:UIControlStateNormal]; [_selectBtn setBackgroundImage:[self createImageWithColor:[UIColor colorWithHexString:LINECOLOR]] forState:UIControlStateHighlighted]; [_selectBtn addTarget:self action:@selector(selectBtnSelector:) forControlEvents:UIControlEventTouchUpInside]; } return _selectBtn; } -(UILabel *)title{ if (!_title) { _title = [[UILabel alloc] initWithFrame:CGRectZero]; _title.textColor = [UIColor colorWithHexString:TextBlack]; _title.font = appFont(18, NO); _title.numberOfLines = 0; _title.backgroundColor = [UIColor clearColor]; _title.lineBreakMode = NSLineBreakByWordWrapping; } return _title; } -(UILabel *)statu{ if (!_statu) { _statu = [[UILabel alloc]init]; _statu.textColor = [UIColor colorWithHexString:TextGray]; _statu.font = appFont(11, NO); _statu.backgroundColor = [UIColor clearColor]; } return _statu; } -(UILabel *)time{ if (!_time) { _time = [[UILabel alloc] initWithFrame:CGRectZero]; _time.textColor = [UIColor colorWithHexString:TextGray]; _time.font = appFont(11, NO); _time.backgroundColor = [UIColor clearColor]; } return _time; } -(UIButton *)editBtn{ if (!_editBtn) { _editBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // _time.textAlignment = NSTextAlignmentCenter; [_editBtn setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal]; _editBtn.layer.borderColor = [UIColor colorWithHexString:BLUECOLOR].CGColor; _editBtn.layer.cornerRadius = 3; _editBtn.layer.borderWidth = 1; _editBtn.titleLabel.font = appFont(11, NO); // [_editBtn addTarget:self action:@selector(editSelector:) forControlEvents:UIControlEventTouchUpInside]; } return _editBtn; } -(UIButton *)editBtnBg{ if (!_editBtnBg) { _editBtnBg = [UIButton buttonWithType:UIButtonTypeCustom]; _editBtnBg.backgroundColor = [UIColor clearColor]; [_editBtnBg addTarget:self action:@selector(editSelector:) forControlEvents:UIControlEventTouchUpInside]; } return _editBtnBg; } -(UIView *)line{ if (!_line) { _line = [[UIView alloc] init]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _line; } -(UIImageView *)errorIcon{ if (!_errorIcon) { _errorIcon = [[UIImageView alloc] init]; _errorIcon.image = Image(@"setting/error.png"); } return _errorIcon; } -(UILabel *)errorText{ if (!_errorText) { _errorText = [[UILabel alloc]init]; _errorText.textColor = [UIColor colorWithHexString:@"0x555657"]; _errorText.font = appFont(9, NO); _errorText.numberOfLines = 0; _errorText.lineBreakMode = NSLineBreakByWordWrapping; _errorText.backgroundColor = [UIColor clearColor]; } return _errorText; } - (UILabel*)markLabel { if (!_markLabel) { _markLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _markLabel.backgroundColor = [UIColor colorWithHexString:@"0xc32128"]; _markLabel.layer.cornerRadius = 11/2; _markLabel.clipsToBounds = YES; _markLabel.textAlignment = NSTextAlignmentCenter; _markLabel.textColor = [UIColor whiteColor]; _markLabel.font = appFont(7, NO); _markLabel.hidden = YES; } return _markLabel; } -(void) selectBtnSelector:(UIButton *)btn{ // btn.highlighted = !btn.highlighted; // btn.selected = !btn.selected; // [_selectBtn setBackgroundImage:[self createImageWithColor:[UIColor colorWithHexString:LINECOLOR]] forState:UIControlStateHighlighted]; if ([self.topicInfo.status intValue] == 1 || [self.topicInfo.status intValue] == 3) { if ([self.myCreateDelegate respondsToSelector:@selector(gotoTopicInfo:indexPath:)]) { [self.myCreateDelegate gotoTopicInfo:self.topicInfo indexPath:self.indexPath]; } }else { if ([self.myCreateDelegate respondsToSelector:@selector(gotoCreat:indexPath:)]) { [self.myCreateDelegate gotoCreat:self.topicInfo indexPath:self.indexPath]; } } } -(void) editSelector:(UIButton *)btn{ if ([_topicInfo.status integerValue] ==0 || [_topicInfo.status integerValue] ==2) { if ([self.myCreateDelegate respondsToSelector:@selector(dele:indexPath:)]) { [self.myCreateDelegate dele:_topicInfo indexPath:_indexPath]; } }else{ if ([self.myCreateDelegate respondsToSelector:@selector(edit:indexPath:)]) { [self.myCreateDelegate edit:_topicInfo indexPath:_indexPath]; } } } /** *颜色值转换成图片 */ - (UIImage*) createImageWithColor: (UIColor*) color { CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage*theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return theImage; } -(void)layoutSubviews{ [super layoutSubviews]; if (self.isEditing) { [self sendSubviewToBack:self.contentView]; } self.backView.frame = self.contentView.bounds; self.selectBtn.frame = self.backView.frame; if (0 ==[status integerValue] || 2 == [status integerValue]) { self.title.frame = CGRectMake(15, 10, titleWidth,titleHeight); }else{ self.title.frame = CGRectMake(15, 10, titleWidth,titleHeight); } self.statu.frame = CGRectMake(15, CGRectGetMaxY(self.title.frame), 135/2, 30); self.time.frame = CGRectMake(CGRectGetMaxX(self.statu.frame),CGRectGetMinY(self.statu.frame),100,30); self.editBtn.frame = CGRectMake(CGRectGetMaxX(self.backView.bounds)-50, CGRectGetMaxY(self.title.frame), 35 , 19); self.editBtnBg.frame = CGRectMake(CGRectGetMaxX(self.backView.bounds)-50, 0, 35 , CGRectGetHeight(self.backView.bounds)); if ([status integerValue] ==2) { self.errorText.hidden = NO; self.errorIcon.hidden = NO; self.errorIcon.frame = CGRectMake(15, CGRectGetMaxY(self.statu.frame)+5, 12, 11); self.errorText.frame = CGRectMake(15, CGRectGetMaxY(self.errorIcon.frame)+5, CGRectGetMaxX(self.backView.bounds)-30, errorHeight); self.line.frame = CGRectMake(15, CGRectGetMaxY(self.backView.bounds)-1, gambitCenterPopSize.width-30, 1); }else{ self.errorText.hidden = YES; self.errorIcon.hidden = YES; self.line.frame = CGRectMake(15, CGRectGetMaxY(self.backView.bounds)-1, gambitCenterPopSize.width-30, 1); } self.markLabel.frame = CGRectMake(CGRectGetMaxX(self.title.frame)-5, CGRectGetMinY(self.title.frame)-5, 11, 11); } @end