XDBarCell.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #import "XDBarCell.h"
  2. @implementation XDBarCell
  3. - (void)awakeFromNib {
  4. [super awakeFromNib];
  5. // Initialization code
  6. }
  7. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  8. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  9. if (self) {
  10. [self createUI];
  11. }
  12. return self;
  13. }
  14. - (void)createUI{
  15. //x轴线
  16. UIView *line = [[UIView alloc] init];
  17. line.backgroundColor = ColorWithHEAL;
  18. [self.contentView addSubview:line];
  19. _lineView = line;
  20. //柱形
  21. UIView *view = [[UIView alloc] init];
  22. view.backgroundColor = ColorWithHEAL;
  23. [self.contentView addSubview:view];
  24. _barView = view;
  25. UILabel *label = [[UILabel alloc] init];
  26. label.textAlignment = NSTextAlignmentCenter;
  27. label.font = Font_xi_PingFangSC_Light_size(14);
  28. label.textColor = [UIColor grayColor];
  29. [self.contentView addSubview:label];
  30. _xLabel = label;
  31. label = [[UILabel alloc] init];
  32. label.textAlignment = NSTextAlignmentCenter;
  33. label.font = Font_xi_PingFangSC_Light_size(14);
  34. label.textColor = [UIColor grayColor];
  35. [self.contentView addSubview:label];
  36. _numLabel = label;
  37. }
  38. -(void)setBarWith:(CGFloat)barWith {
  39. _barWith = barWith;
  40. if (_cellHeight > 0.0) {
  41. _lineView.frame = CGRectMake(_barWith, -20,2,_cellHeight + 40);
  42. //先旋转 在设置坐标0.0
  43. _xLabel.transform = CGAffineTransformMakeRotation(M_PI / 2);
  44. _xLabel.frame = CGRectMake(0.0, 0.0, _barWith, _cellHeight);
  45. }
  46. }
  47. - (void)setDataDic:(NSDictionary *)dataDic {
  48. _dataDic = dataDic;
  49. NSString *xTit = dataDic[@"key"];
  50. if (xTit.length > 6) {
  51. xTit = [xTit substringToIndex:6];
  52. }
  53. _xLabel.text = xTit;
  54. //[UIScreen mainScreen].bounds.size.width * 0.67 设置的图的高的三分之二
  55. CGFloat height = [dataDic[@"value"] floatValue]/_maxValue*(_cellLong - _barWith - 50);
  56. if (height == 0) {
  57. height = 1.5;
  58. }
  59. _barView.frame = CGRectMake(CGRectGetMaxX(_lineView.frame),_cellHeight/2.0 - _barWith/2.0, height,_barWith);
  60. //先旋转 在设置坐标0.0
  61. _numLabel.transform = CGAffineTransformMakeRotation(M_PI / 2);
  62. _numLabel.frame = CGRectMake(CGRectGetMaxX(_lineView.frame) + height, 0.0, 30, _cellHeight);
  63. _numLabel.text = [NSString stringWithFormat:@"%@",dataDic[@"value"]];
  64. }
  65. - (void)setCellHeight:(CGFloat)cellHei barWidth:(CGFloat)barW maxValue:(CGFloat)maxV dataDictionary:(NSDictionary *)dic {
  66. _maxValue = maxV;
  67. //顺序不能错哈
  68. self.cellHeight = cellHei;
  69. self.barWith = barW;
  70. self.dataDic = dic;
  71. }
  72. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  73. [super setSelected:selected animated:animated];
  74. // Configure the view for the selected state
  75. }
  76. @end