美文网首页
iOS 自定义cell,字符串length==0时赋值为空,否则

iOS 自定义cell,字符串length==0时赋值为空,否则

作者: LoveBe | 来源:发表于2020-11-25 15:17 被阅读0次
    #import "AttendanceCell.h"
    
    @implementation AttendanceCell
    
    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
        if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
            _identifier = reuseIdentifier;
            [self initBaseView];
            if ([reuseIdentifier isEqualToString:@"myList"]) {//列表
                [self initMyListView];
            } else if ([reuseIdentifier isEqualToString:@"infoHeader"]) {//详情基本信息
                [self initInfoHeaderView];
            } else if ([reuseIdentifier isEqualToString:@"info"]) {//详情基本信息
                [self initInfoView];
            } else if ([reuseIdentifier isEqualToString:@"approval"]) {//详情审批信息
                [self initApprovalView];
            }
        }
        return self;
    }
    
    - (void)initBaseView {
        _baseView = [[UIView alloc] init];
        _baseView.layer.masksToBounds = YES;
        _baseView.layer.cornerRadius = 5;
        _baseView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_baseView];
        [_baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(5, 10, 5, 10));
        }];
    }
    
    #pragma mark - initView
    //列表
    - (void)initMyListView {
        _typeLabel = [[UILabel alloc]init];
        _typeLabel.numberOfLines = 0;
        _typeLabel.font = [UIFont systemFontOfSize:18.0];
        _typeLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_typeLabel];
        [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10);
            make.left.offset(15);
            make.right.offset(-15);
        }];
        
        _aStateLabel = [[UILabel alloc]init];
        _aStateLabel.numberOfLines = 0;
        _aStateLabel.font = [UIFont systemFontOfSize:14.0];
        _aStateLabel.textColor = [UIColor grayColor];
        [_aStateLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_aStateLabel];
        [_aStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10);
            make.right.offset(-15);
        }];
        
        _nameStrLabel = [[UILabel alloc]init];
        _nameStrLabel.font = [UIFont systemFontOfSize:16.0];
        _nameStrLabel.textColor = [UIColor grayColor];
        [_nameLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_nameStrLabel];
        [_nameStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_typeLabel.mas_bottom).offset(10);
            make.left.offset(15);
        }];
        
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.numberOfLines = 0;
        _nameLabel.font = [UIFont systemFontOfSize:16.0];
        _nameLabel.textColor = [UIColor grayColor];
        [_baseView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_typeLabel.mas_bottom).offset(10);
            make.left.equalTo(_nameStrLabel.mas_right);
            make.right.offset(-15);
        }];
        
        _timeStrLabel = [[UILabel alloc]init];
        _timeStrLabel.font = [UIFont systemFontOfSize:16.0];
        _timeStrLabel.textColor = [UIColor grayColor];
        [_timeStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_timeStrLabel];
        [_timeStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_nameLabel.mas_bottom).offset(10);
            make.left.offset(15);
        }];
        
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.numberOfLines = 0;
        _timeLabel.font = [UIFont systemFontOfSize:16.0];
        _timeLabel.textColor = [UIColor grayColor];
        [_baseView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_nameLabel.mas_bottom).offset(10);
            make.left.equalTo(_timeStrLabel.mas_right);
            make.right.offset(-15);
            make.bottom.offset(-10);
        }];
    }
    
    #pragma mark -详情
    //显示类型和发起时间
    - (void)initInfoHeaderView {
        _typeLabel = [[UILabel alloc]init];
        _typeLabel.numberOfLines = 0;
        _typeLabel.font = [UIFont systemFontOfSize:21.0];
        _typeLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_typeLabel];
        [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10);
            make.left.offset(5);
            make.right.offset(-5);
        }];
        
        _dateLabel = [[UILabel alloc]init];
        _dateLabel.numberOfLines = 0;
        _dateLabel.font = [UIFont systemFontOfSize:14.0];
        _dateLabel.textColor = [UIColor grayColor];
        [_baseView addSubview:_dateLabel];
        [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_typeLabel.mas_bottom).offset(10);
            make.left.offset(5);
            make.right.offset(-5);
            make.bottom.offset(-10);
        }];
    }
    
    //基本信息
    - (void)initInfoView {
        _nameStrLabel = [[UILabel alloc]init];
        _nameStrLabel.font = [UIFont systemFontOfSize:16.0];
        _nameStrLabel.textColor = [UIColor grayColor];
        [_nameStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_nameStrLabel];
        [_nameStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10);
            make.left.offset(5);
        }];
        
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.numberOfLines = 0;
        _nameLabel.font = [UIFont systemFontOfSize:16.0];
        _nameLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_nameStrLabel.mas_top);
            make.left.equalTo(_nameStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _typeStrLabel = [[UILabel alloc]init];
        _typeStrLabel.numberOfLines = 0;
        _typeStrLabel.font = [UIFont systemFontOfSize:16.0];
        _typeStrLabel.textColor = [UIColor grayColor];
        [_typeStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_typeStrLabel];
        [_typeStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_nameLabel.mas_bottom).offset(10);
            make.left.offset(5);
        }];
        
        _typeLabel = [[UILabel alloc]init];
        _typeLabel.numberOfLines = 0;
        _typeLabel.font = [UIFont systemFontOfSize:16.0];
        _typeLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_typeLabel];
        [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_typeStrLabel.mas_top);
            make.left.equalTo(_typeStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _timeStrLabel = [[UILabel alloc]init];
        _timeStrLabel.font = [UIFont systemFontOfSize:16.0];
        _timeStrLabel.textColor = [UIColor grayColor];
        [_timeStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_timeStrLabel];
        [_timeStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_typeLabel.mas_bottom).offset(10);
            make.left.offset(5);
        }];
        
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.numberOfLines = 0;
        _timeLabel.font = [UIFont systemFontOfSize:16.0];
        _timeLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_timeStrLabel.mas_top);
            make.left.equalTo(_timeStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _sundayStrLabel = [[UILabel alloc]init];
        _sundayStrLabel.font = [UIFont systemFontOfSize:16.0];
        _sundayStrLabel.textColor = [UIColor grayColor];
        [_sundayStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_sundayStrLabel];
        [_sundayStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5);
        }];
    
        _sundayLabel = [[UILabel alloc]init];
        _sundayLabel.numberOfLines = 0;
        _sundayLabel.font = [UIFont systemFontOfSize:16.0];
        _sundayLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_sundayLabel];
        [_sundayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_sundayStrLabel.mas_top);
            make.left.equalTo(_sundayStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _qdDateStrLabel = [[UILabel alloc]init];
        _qdDateStrLabel.font = [UIFont systemFontOfSize:16.0];
        _qdDateStrLabel.textColor = [UIColor grayColor];
        [_qdDateStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_qdDateStrLabel];
        [_qdDateStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5);
        }];
        
        _qdDateLabel = [[UILabel alloc]init];
        _qdDateLabel.numberOfLines = 0;
        _qdDateLabel.font = [UIFont systemFontOfSize:16.0];
        _qdDateLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_qdDateLabel];
        [_qdDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_qdDateStrLabel.mas_top);
            make.left.equalTo(_qdDateStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _qtDateStrLabel = [[UILabel alloc]init];
        _qtDateStrLabel.font = [UIFont systemFontOfSize:16.0];
        _qtDateStrLabel.textColor = [UIColor grayColor];
        [_qtDateStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_qtDateStrLabel];
        [_qtDateStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5);
        }];
        
        _qtDateLabel = [[UILabel alloc]init];
        _qtDateLabel.numberOfLines = 0;
        _qtDateLabel.font = [UIFont systemFontOfSize:16.0];
        _qtDateLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_qtDateLabel];
        [_qtDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_qtDateStrLabel.mas_top);
            make.left.equalTo(_qtDateStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _reasonStrLabel = [[UILabel alloc]init];
        _reasonStrLabel.font = [UIFont systemFontOfSize:16.0];
        _reasonStrLabel.textColor = [UIColor grayColor];
        [_reasonStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_reasonStrLabel];
        [_reasonStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_qtDateLabel.mas_bottom).offset(10);
            make.left.offset(5);
        }];
        
        _reasonLabel = [[UILabel alloc]init];
        _reasonLabel.numberOfLines = 0;
        _reasonLabel.font = [UIFont systemFontOfSize:16.0];
        _reasonLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_reasonLabel];
        [_reasonLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_reasonStrLabel.mas_top);
            make.left.equalTo(_reasonStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _aStateStrLabel = [[UILabel alloc]init];
        _aStateStrLabel.font = [UIFont systemFontOfSize:16.0];
        _aStateStrLabel.textColor = [UIColor grayColor];
        [_aStateStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_aStateStrLabel];
        [_aStateStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5);
        }];
        
        _aStateLabel = [[UILabel alloc]init];
        _aStateLabel.numberOfLines = 0;
        _aStateLabel.font = [UIFont systemFontOfSize:16.0];
        _aStateLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_aStateLabel];
        [_aStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_aStateStrLabel.mas_top);
            make.left.equalTo(_aStateStrLabel.mas_right);
            make.right.offset(-5);
            make.bottom.offset(-10);
        }];
        
        _sundayStrConstraint = [NSLayoutConstraint constraintWithItem:_sundayStrLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_timeLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:10];
        _qdDateStrConstraint = [NSLayoutConstraint constraintWithItem:_qdDateStrLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_sundayLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:10];
        _qtDateStrConstraint = [NSLayoutConstraint constraintWithItem:_qtDateStrLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_qdDateLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:10];
        _aStateStrConstraint = [NSLayoutConstraint constraintWithItem:_aStateStrLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_reasonLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:10];
        [self.contentView addConstraints:[NSArray arrayWithObjects:_sundayStrConstraint,_qdDateStrConstraint,_qtDateStrConstraint,_aStateStrConstraint, nil]];
    }
    
    //审批信息
    - (void)initApprovalView {
        _sNameStrLabel = [[UILabel alloc]init];
        _sNameStrLabel.font = [UIFont systemFontOfSize:16.0];
        _sNameStrLabel.textColor = [UIColor grayColor];
        [_sNameStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_sNameStrLabel];
        [_sNameStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10);
            make.left.offset(5);
        }];
        
        _sNameLabel = [[UILabel alloc]init];
        _sNameLabel.numberOfLines = 0;
        _sNameLabel.font = [UIFont systemFontOfSize:16.0];
        _sNameLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_sNameLabel];
        [_sNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_sNameStrLabel.mas_top);
            make.left.equalTo(_sNameStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _sStateStrLabel = [[UILabel alloc]init];
        _sStateStrLabel.font = [UIFont systemFontOfSize:16.0];
        _sStateStrLabel.textColor = [UIColor grayColor];
        [_sStateStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_sStateStrLabel];
        [_sStateStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_sNameLabel.mas_bottom).offset(10);
            make.left.offset(5);
        }];
        
        _sStateLabel = [[UILabel alloc]init];
        _sStateLabel.numberOfLines = 0;
        _sStateLabel.font = [UIFont systemFontOfSize:16.0];
        _sStateLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_sStateLabel];
        [_sStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_sStateStrLabel.mas_top);
            make.left.equalTo(_sStateStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _sOpinionStrLabel = [[UILabel alloc]init];
        _sOpinionStrLabel.font = [UIFont systemFontOfSize:16.0];
        _sOpinionStrLabel.textColor = [UIColor grayColor];
        [_sOpinionStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_sOpinionStrLabel];
        [_sOpinionStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5);
        }];
        
        _sOpinionLabel = [[UILabel alloc]init];
        _sOpinionLabel.numberOfLines = 0;
        _sOpinionLabel.font = [UIFont systemFontOfSize:16.0];
        _sOpinionLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_sOpinionLabel];
        [_sOpinionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_sOpinionStrLabel.mas_top);
            make.left.equalTo(_sOpinionStrLabel.mas_right);
            make.right.offset(-5);
        }];
        
        _sDateStrLabel = [[UILabel alloc]init];
        _sDateStrLabel.font = [UIFont systemFontOfSize:16.0];
        _sDateStrLabel.textColor = [UIColor grayColor];
        [_sDateStrLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [_baseView addSubview:_sDateStrLabel];
        [_sDateStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5);
        }];
        
        _sDateLabel = [[UILabel alloc]init];
        _sDateLabel.numberOfLines = 0;
        _sDateLabel.font = [UIFont systemFontOfSize:16.0];
        _sDateLabel.textColor = [UIColor blackColor];
        [_baseView addSubview:_sDateLabel];
        [_sDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_sDateStrLabel.mas_top);
            make.left.equalTo(_sDateStrLabel.mas_right);
            make.right.offset(-5);
            make.bottom.offset(-10);
        }];
        
        _sOpinionStrConstraint = [NSLayoutConstraint constraintWithItem:_sOpinionStrLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_sStateLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:10];
        _sDateStrConstraint = [NSLayoutConstraint constraintWithItem:_sDateStrLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_sOpinionLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:10];
        [self.contentView addConstraints:[NSArray arrayWithObjects:_sOpinionStrConstraint,_sDateStrConstraint, nil]];
    }
    
    #pragma mark - 赋值
    - (void)setModel:(PModel *)model {
        if ([_identifier isEqualToString:@"myList"]) {//列表
            _typeLabel.text = [model.contentDict[@"aflag"]length]>0 ? model.contentDict[@"aflag"] : @" ";
            _aStateLabel.text = [model.contentDict[@"flag"]length]>0 ? model.contentDict[@"flag"] : @" ";
            ///修改样式
            if ([model.contentDict[@"flag"]isEqualToString:languageStr(@"正常")] || [model.contentDict[@"flag"]isEqualToString:languageStr(@"通过")]) {//正常、通过显示蓝色
                _aStateLabel.textColor = COLOR_MAIN_BLUE;
            } else if ([model.contentDict[@"flag"]isEqualToString:languageStr(@"正在审批")]) {//正在审批显示橘黄色
                _aStateLabel.textColor = [UIColor orangeColor];
            } else if ([model.contentDict[@"flag"]isEqualToString:languageStr(@"无效")] || [model.contentDict[@"flag"]isEqualToString:languageStr(@"未通过")]) {//无效、未通过显示红色
                _aStateLabel.textColor = [UIColor redColor];
            }
            _nameStrLabel.text = [NSString stringWithFormat:@"%@ :  ",([model.contentDict[@"myType"]isEqual:languageStr(@"我的申请")]) ? languageStr(@"审  批  人") : languageStr(@"申  请  人")];
            _nameLabel.text = [model.contentDict[@"fname"]length]>0 ? model.contentDict[@"fname"] : @" ";
            _timeStrLabel.text = [NSString stringWithFormat:@"%@ :  ",([model.contentDict[@"applyType"] isEqualToString:languageStr(@"外勤")] || [model.contentDict[@"applyType"] isEqualToString:languageStr(@"异常处理")]) ? languageStr(@"申请时间") : languageStr(@"申请范围")];
            _timeLabel.text = [model.contentDict[@"ariqi"]length]>0?model.contentDict[@"ariqi"]:@" ";
        } else if ([_identifier isEqualToString:@"infoHeader"]) {//详情头视图
            if ([model.contentDict[@"applyType"]isEqualToString:languageStr(@"外勤")]) {
                _typeLabel.text = [model.contentDict[@"sqdate"]length]>0 ? model.contentDict[@"sqdate"] : @" ";
            } else if ([model.contentDict[@"applyType"]isEqualToString:languageStr(@"异常处理")]) {
                _typeLabel.text = [model.contentDict[@"applytype"]length]>0 ? model.contentDict[@"applytype"] : @" ";
            } else {
                _typeLabel.text = [model.contentDict[@"aflag"]length]>0 ? model.contentDict[@"aflag"] : @" ";
            }
            _dateLabel.text = [model.contentDict[@"adate"]length]>0 ? model.contentDict[@"adate"] : @" ";
        } else if ([_identifier isEqualToString:@"info"]) {//详情基本信息
            _nameStrLabel.text = [NSString stringWithFormat:@"%@        ", languageStr(@"申请人")];
            _nameLabel.text = [model.contentDict[@"sqr"]length]>0 ? model.contentDict[@"sqr"] : @" ";
            _timeStrLabel.text = [NSString stringWithFormat:@"%@    ",[model.contentDict[@"applyType"]isEqualToString:languageStr(@"异常处理")] ? languageStr(@"考勤日期") : languageStr(@"申请范围")];
            _timeLabel.text = [model.contentDict[@"sqdate"]length]>0 ? model.contentDict[@"sqdate"] : @" ";
            if (([model.contentDict[@"applytype"] isEqualToString:languageStr(@"请假")] || [model.contentDict[@"applytype"] isEqualToString:languageStr(@"出差")]) && [model.contentDict[@"skipsunday"]length] > 0) {
                _sundayStrLabel.text = [NSString stringWithFormat:@"%@    ",languageStr(@"跳过周日")];
                _sundayLabel.text = [model.contentDict[@"skipsunday"]intValue]==1 ? languageStr(@"是") : languageStr(@"否");
            } else if ([model.contentDict[@"applytype"] isEqualToString:languageStr(@"加班")] && [model.contentDict[@"jbflag"]length]>0) {
                _sundayStrLabel.text = [NSString stringWithFormat:@"%@    ",languageStr(@"加班用于")];
                _sundayLabel.text = [model.contentDict[@"jbflag"]length]>0 ? model.contentDict[@"jbflag"] : @" ";
            } else {
                _sundayStrLabel.text = @"";
                _sundayLabel.text = @"";
            }
            _reasonStrLabel.text = [NSString stringWithFormat:@"%@    ",languageStr(@"申请原因")];
            _reasonLabel.text = [__Decrypt(model.contentDict[@"reason"], 2) length]>0?__Decrypt(model.contentDict[@"reason"], 2):@" ";
            _dateStrLabel.text = [NSString stringWithFormat:@"%@    ", languageStr(@"申请时间")];
            _dateLabel.text = [model.contentDict[@"adate"]length]>0 ? model.contentDict[@"adate"] : @" ";
            _typeStrLabel.text = [NSString stringWithFormat:@"%@    ", languageStr(@"申请类型")];
            if ([model.contentDict[@"applyType"]isEqualToString:languageStr(@"异常处理")]) {
                _typeLabel.text = model.contentDict[@"applyType"];
                _qdDateStrLabel.text = [NSString stringWithFormat:@"%@    ", languageStr(@"签到时间")];
                _qdDateLabel.text = [model.contentDict[@"zflag"]length]>0 ? model.contentDict[@"zflag"] : @" ";
                _qtDateStrLabel.text = [NSString stringWithFormat:@"%@    ", languageStr(@"签退时间")];
                _qtDateLabel.text = [model.contentDict[@"aflag"]length]>0 ? model.contentDict[@"aflag"] : @" ";
            } else {
                if ([model.contentDict[@"qjtype"]length] > 0) {
                    _typeLabel.text = [NSString stringWithFormat:@"%@(%@)",model.contentDict[@"applytype"],model.contentDict[@"qjtype"]];
                } else {
                    _typeLabel.text = [model.contentDict[@"applytype"]length]>0 ? model.contentDict[@"applytype"] : @" ";
                }
                _aStateStrLabel.text = [NSString stringWithFormat:@"%@    ", languageStr(@"审批状态")];
                _aStateLabel.text = [model.contentDict[@"zflag"]length]>0 ? model.contentDict[@"zflag"] : @" ";
                ///修改样式
                if ([model.contentDict[@"zflag"]isEqualToString:languageStr(@"通过")]) {//通过显示蓝色
                    _aStateLabel.textColor = COLOR_MAIN_BLUE;
                } else if ([model.contentDict[@"zflag"]isEqualToString:languageStr(@"正在审批")]) {//正在审批显示橘黄色
                    _aStateLabel.textColor = [UIColor orangeColor];
                } else if ([model.contentDict[@"zflag"]isEqualToString:languageStr(@"未通过")]) {//未通过显示红色
                    _aStateLabel.textColor = [UIColor redColor];
                }
            }
        } else if ([_identifier isEqualToString:@"approval"]) {//详情审批信息
            NSIndexPath *indexPath = model.contentDict[@"indexPath"];
            if ([model.contentDict[@"applyType"]isEqualToString:languageStr(@"替班")] && indexPath.row == 0) {//第一行显示替班人
                _sNameStrLabel.text = [NSString stringWithFormat:@"%@        ", languageStr(@"替班人")];
            } else {
                _sNameStrLabel.text = [NSString stringWithFormat:@"%@        ", languageStr(@"审批人")];
            }
            _sNameLabel.text = [model.contentDict[@"spr"]length]>0 ? model.contentDict[@"spr"] : @" ";
            _sStateStrLabel.text = [NSString stringWithFormat:@"%@    ", languageStr(@"审批状态")];
            _sStateLabel.text = [model.contentDict[@"flag"]length]>0 ? model.contentDict[@"flag"] : @" ";
            
            ///修改样式
            if ([model.contentDict[@"flag"]isEqualToString:languageStr(@"正常")] || [model.contentDict[@"flag"]isEqualToString:languageStr(@"审批通过")]) {//正常、通过显示蓝色
                _sStateLabel.textColor = COLOR_MAIN_BLUE;
            } else if ([model.contentDict[@"flag"]isEqualToString:languageStr(@"正在审批")]) {//正在审批显示橘黄色
                _sStateLabel.textColor = [UIColor orangeColor];
            } else if ([model.contentDict[@"flag"]isEqualToString:languageStr(@"无效")] || [model.contentDict[@"flag"]isEqualToString:languageStr(@"审批未通过")]) {//无效、未通过显示红色
                _sStateLabel.textColor = [UIColor redColor];
            }
            //length==0时必须赋值为空,否则会出现显示错位的问题
            if ([__Decrypt(model.contentDict[@"shenpiyj"], 2)length] > 0) {
                _sOpinionStrLabel.text = [NSString stringWithFormat:@"%@    ",languageStr(@"审批意见")];
                _sOpinionLabel.text = __Decrypt(model.contentDict[@"shenpiyj"], 2);
            } else {
                _sOpinionStrLabel.text = @"";
                _sOpinionLabel.text = @"";
            }
            //length==0时必须赋值为空,否则会出现显示错位的问题
            if (![model.contentDict[@"applyType"]isEqualToString:languageStr(@"外勤")] && [model.contentDict[@"shenpiriqi"]length]>0) {
                _sDateStrLabel.text = [NSString stringWithFormat:@"%@    ", languageStr(@"审批日期")];
                _sDateLabel.text = model.contentDict[@"shenpiriqi"];
            } else {
                _sDateStrLabel.text = @"";
                _sDateLabel.text = @"";
            }
        }
    }
    
    @end

    相关文章

      网友评论

          本文标题:iOS 自定义cell,字符串length==0时赋值为空,否则

          本文链接:https://www.haomeiwen.com/subject/hcjniktx.html