#import "XDBarCell.h" @implementation XDBarCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self createUI]; } return self; } - (void)createUI{ //x轴线 UIView *line = [[UIView alloc] init]; line.backgroundColor = ColorWithHEAL; [self.contentView addSubview:line]; _lineView = line; //柱形 UIView *view = [[UIView alloc] init]; view.backgroundColor = ColorWithHEAL; [self.contentView addSubview:view]; _barView = view; UILabel *label = [[UILabel alloc] init]; label.textAlignment = NSTextAlignmentCenter; label.font = Font_xi_PingFangSC_Light_size(14); label.textColor = [UIColor grayColor]; [self.contentView addSubview:label]; _xLabel = label; label = [[UILabel alloc] init]; label.textAlignment = NSTextAlignmentCenter; label.font = Font_xi_PingFangSC_Light_size(14); label.textColor = [UIColor grayColor]; [self.contentView addSubview:label]; _numLabel = label; } -(void)setBarWith:(CGFloat)barWith { _barWith = barWith; if (_cellHeight > 0.0) { _lineView.frame = CGRectMake(_barWith, -20,2,_cellHeight + 40); //先旋转 在设置坐标0.0 _xLabel.transform = CGAffineTransformMakeRotation(M_PI / 2); _xLabel.frame = CGRectMake(0.0, 0.0, _barWith, _cellHeight); } } - (void)setDataDic:(NSDictionary *)dataDic { _dataDic = dataDic; NSString *xTit = dataDic[@"key"]; if (xTit.length > 6) { xTit = [xTit substringToIndex:6]; } _xLabel.text = xTit; //[UIScreen mainScreen].bounds.size.width * 0.67 设置的图的高的三分之二 CGFloat height = [dataDic[@"value"] floatValue]/_maxValue*(_cellLong - _barWith - 50); if (height == 0) { height = 1.5; } _barView.frame = CGRectMake(CGRectGetMaxX(_lineView.frame),_cellHeight/2.0 - _barWith/2.0, height,_barWith); //先旋转 在设置坐标0.0 _numLabel.transform = CGAffineTransformMakeRotation(M_PI / 2); _numLabel.frame = CGRectMake(CGRectGetMaxX(_lineView.frame) + height, 0.0, 30, _cellHeight); _numLabel.text = [NSString stringWithFormat:@"%@",dataDic[@"value"]]; } - (void)setCellHeight:(CGFloat)cellHei barWidth:(CGFloat)barW maxValue:(CGFloat)maxV dataDictionary:(NSDictionary *)dic { _maxValue = maxV; //顺序不能错哈 self.cellHeight = cellHei; self.barWith = barW; self.dataDic = dic; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end