热更新demo

myCreateCell.m 13KB

    // // 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)UIImageView *timeIcon; @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 = UITableViewCellSelectionStyleNone; self.clipsToBounds = YES; self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; [self.contentView addSubview:self.backView]; [self.contentView addSubview:self.markLabel]; [self.backView addSubview:self.title]; [self.backView addSubview:self.statu]; [self.backView addSubview:self.time]; [self.backView addSubview:self.timeIcon]; [self.backView addSubview:self.errorIcon]; [self.backView addSubview:self.errorText]; [self.backView addSubview:self.editBtn]; [self.backView addSubview:self.editBtnBg]; [self.backView addSubview:self.line]; } return self; } #pragma mark - view -(UIView *)backView{ if (!_backView) { _backView = [[UIView alloc] init]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } -(UIButton *)selectBtn{ if (!_selectBtn) { _selectBtn = [UIButton new]; [_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 new]; _title.textColor = [UIColor colorWithHexString:TextBlack]; _title.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _title.numberOfLines = 0; _title.backgroundColor = [UIColor clearColor]; _title.lineBreakMode = NSLineBreakByWordWrapping; } return _title; } -(UILabel *)statu{ if (!_statu) { _statu = [UILabel new]; _statu.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _statu.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _statu.backgroundColor = [UIColor clearColor]; } return _statu; } -(UILabel *)time{ if (!_time) { _time = [UILabel new]; _time.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _time.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _time.backgroundColor = [UIColor clearColor]; } return _time; } -(UIImageView *)timeIcon{ if (!_timeIcon) { _timeIcon = [UIImageView new]; _timeIcon.image = Image(@"topic/timeImg.png"); } return _timeIcon; } -(UIButton *)editBtn{ if (!_editBtn) { _editBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_editBtn setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal]; _editBtn.layer.borderColor = [UIColor colorWithHexString:BLUECOLOR].CGColor; // _editBtn.titleLabel.textAlignment = NSTextAlignmentCenter; _editBtn.layer.cornerRadius = 3; _editBtn.layer.borderWidth = 1; _editBtn.userInteractionEnabled = NO; _editBtn.titleLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); } return _editBtn; } -(UIButton *)editBtnBg{ if (!_editBtnBg) { _editBtnBg = [UIButton buttonWithType:UIButtonTypeCustom]; _editBtnBg.backgroundColor = [UIColor clearColor]; _editBtnBg.userInteractionEnabled = YES; [_editBtnBg addTarget:self action:@selector(editSelector:) forControlEvents:UIControlEventTouchUpInside]; } return _editBtnBg; } -(UIView *)line{ if (!_line) { _line = [UIView new]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _line; } -(UIImageView *)errorIcon{ if (!_errorIcon) { _errorIcon = [[UIImageView alloc] init]; _errorIcon.image = Image(@"other/myCreateError.png"); } return _errorIcon; } -(UILabel *)errorText{ if (!_errorText) { _errorText = [UILabel new]; _errorText.textColor = [UIColor colorWithHexString:TextBlack]; _errorText.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _errorText.numberOfLines = 0; _errorText.textAlignment = NSTextAlignmentLeft; _errorText.lineBreakMode = NSLineBreakByWordWrapping; _errorText.backgroundColor = [UIColor clearColor]; } return _errorText; } - (UILabel*)markLabel { if (!_markLabel) { _markLabel = [UILabel new]; _markLabel.backgroundColor = [UIColor colorWithHexString:@"0xc32128"]; _markLabel.layer.cornerRadius = 15/2; _markLabel.clipsToBounds = YES; _markLabel.textAlignment = NSTextAlignmentCenter; _markLabel.textColor = [UIColor whiteColor]; _markLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _markLabel.hidden = YES; } return _markLabel; } -(void) selectBtnSelector:(UIButton *)btn{ 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; } #pragma mark -- set data - (void)setTopicInfo:(TopicInfoBO *)topInfo { _topicInfo = topInfo; // errorHeight = 0; status = topInfo.status; self.title.text = topInfo.title; titleHeight = [self.title sizeThatFits:CGSizeMake(rect_screen.size.width -40, NO)].height; self.time.text = topInfo.publishTime; self.statu.text = [self statuName:topInfo]; if (!topInfo.rejectReson || isBlankString(topInfo.rejectReson)) { errorHeight = 0; self.errorText.text = @""; }else{ self.errorText.text = [NSString stringWithFormat:@"说明: %@", topInfo.rejectReson]; errorHeight = [self.errorText sizeThatFits:CGSizeMake(rect_screen.size.width - 62, 0)].height; } 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; } 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 = @""; } [self relayout]; } -(void)setIndexPath:(NSIndexPath *)index{ _indexPath = index; } //状态:0- 已提交待审核;1- 进行中;2- 审核不通过;3- 关闭 -(NSString *)statuName:(TopicInfoBO *)topic{ NSString *str; if ([topic.status integerValue] ==0) { str = @"待审核"; self.errorIcon.hidden = YES; self.errorText.hidden = YES; }else if ([topic.status integerValue] ==1) { if ([topic.replyedNum integerValue] <=0) {//【需求】话题:增加提问征集中的状态(bug:4323) str = @"提问征集中"; }else{ str = @"进行中..."; } self.errorIcon.hidden = YES; self.errorText.hidden = YES; }else if ([topic.status integerValue] ==2) { str = @"未通过"; self.errorIcon.hidden = NO; self.errorText.hidden = NO; }else if ([topic.status integerValue] ==3) { str = @"已关闭提问"; self.errorIcon.hidden = YES; self.errorText.hidden = YES; } return str; } -(void)layoutSubviews{ if (self.isEditing) { [self sendSubviewToBack:self.contentView]; } [self.backView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).equalTo(10); make.right.equalTo(self.contentView.right).equalTo(-10); make.top.equalTo(self.contentView.top).equalTo(10); make.bottom.equalTo(self.contentView.bottom); }]; [self.markLabel makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.backView.right).offset(15/2); make.width.equalTo(@15); make.top.equalTo(self.backView.top).offset(-15/2); make.height.equalTo(@15); }]; [self.statu makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.title.left); make.width.equalTo(@60); make.top.equalTo(self.title.bottom).offset(12); make.height.mas_equalTo(10); }]; [self.timeIcon makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.statu.right).offset(5); make.width.mas_equalTo(10); make.top.equalTo(self.statu.top); make.height.mas_equalTo(10); }]; [self.time makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.timeIcon.right).offset(5); make.right.mas_equalTo(@100); make.top.equalTo(self.statu.top); make.height.mas_equalTo(10); }]; [self.editBtn makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.right).offset(-40); make.width.equalTo(@30); make.top.equalTo(self.statu.top).offset(-2); make.height.equalTo(@15); }]; [self.editBtnBg makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.right).offset(-50); make.width.equalTo(@50); make.top.equalTo(self.statu.top).offset(-10); make.height.equalTo(@30); }]; [self.line makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left); make.right.equalTo(self.backView.right); make.top.equalTo(self.backView.bottom).offset(-1); make.bottom.equalTo(self.backView.bottom); }]; [super layoutSubviews]; } -(void) relayout{ [self.title remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.right.equalTo(self.backView.right).offset(-10); make.top.equalTo(self.backView.top).offset(15); make.height.equalTo(titleHeight+5); }]; [self.errorIcon remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.title.left); make.width.equalTo(@12); make.top.equalTo(self.statu.bottom).offset(10); make.height.equalTo(@11); }]; [self.errorText remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.errorIcon.right).offset(5); make.right.equalTo(self.backView.right).offset(-10); make.top.equalTo(self.errorIcon.top); make.height.equalTo(errorHeight); }]; } @end