Antoine Gamond

Add font and color customization for xLabel and yLabel in PNLineChart

@@ -33,6 +33,10 @@ @@ -33,6 +33,10 @@
33 33
34 @property (nonatomic) CGFloat xLabelWidth; 34 @property (nonatomic) CGFloat xLabelWidth;
35 35
  36 +@property (nonatomic) UIFont *xLabelFont;
  37 +
  38 +@property (nonatomic) UIColor *xLabelColor;
  39 +
36 @property (nonatomic) CGFloat yValueMax; 40 @property (nonatomic) CGFloat yValueMax;
37 41
38 @property (nonatomic) CGFloat yValueMin; 42 @property (nonatomic) CGFloat yValueMin;
@@ -41,6 +45,10 @@ @@ -41,6 +45,10 @@
41 45
42 @property (nonatomic) CGFloat yLabelHeight; 46 @property (nonatomic) CGFloat yLabelHeight;
43 47
  48 +@property (nonatomic) UIFont *yLabelFont;
  49 +
  50 +@property (nonatomic) UIColor *yLabelColor;
  51 +
44 @property (nonatomic) CGFloat chartCavanHeight; 52 @property (nonatomic) CGFloat chartCavanHeight;
45 53
46 @property (nonatomic) CGFloat chartCavanWidth; 54 @property (nonatomic) CGFloat chartCavanWidth;
@@ -71,14 +71,17 @@ @@ -71,14 +71,17 @@
71 if (yStep == 0.0) { 71 if (yStep == 0.0) {
72 PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight, _chartMargin, _yLabelHeight)]; 72 PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight, _chartMargin, _yLabelHeight)];
73 minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0]; 73 minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0];
  74 + [self setCustomStyleForYLabel:minLabel];
74 [self addSubview:minLabel]; 75 [self addSubview:minLabel];
75 76
76 PNChartLabel *midLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight/2, _chartMargin, _yLabelHeight)]; 77 PNChartLabel *midLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight/2, _chartMargin, _yLabelHeight)];
77 midLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax]; 78 midLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax];
  79 + [self setCustomStyleForYLabel:midLabel];
78 [self addSubview:midLabel]; 80 [self addSubview:midLabel];
79 81
80 PNChartLabel *maxLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _chartMargin, _yLabelHeight)]; 82 PNChartLabel *maxLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _chartMargin, _yLabelHeight)];
81 maxLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax * 2]; 83 maxLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax * 2];
  84 + [self setCustomStyleForYLabel:maxLabel];
82 [self addSubview:maxLabel]; 85 [self addSubview:maxLabel];
83 86
84 } else { 87 } else {
@@ -89,6 +92,7 @@ @@ -89,6 +92,7 @@
89 PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (_chartCavanHeight - index * yStepHeight), _chartMargin, _yLabelHeight)]; 92 PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (_chartCavanHeight - index * yStepHeight), _chartMargin, _yLabelHeight)];
90 [label setTextAlignment:NSTextAlignmentRight]; 93 [label setTextAlignment:NSTextAlignmentRight];
91 label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)]; 94 label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)];
  95 + [self setCustomStyleForYLabel:label];
92 [self addSubview:label]; 96 [self addSubview:label];
93 index += 1; 97 index += 1;
94 num -= 1; 98 num -= 1;
@@ -96,7 +100,6 @@ @@ -96,7 +100,6 @@
96 } 100 }
97 } 101 }
98 102
99 -  
100 - (void)setXLabels:(NSArray *)xLabels 103 - (void)setXLabels:(NSArray *)xLabels
101 { 104 {
102 _xLabels = xLabels; 105 _xLabels = xLabels;
@@ -110,6 +113,7 @@ @@ -110,6 +113,7 @@
110 PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(2 * _chartMargin + (index * _xLabelWidth) - (_xLabelWidth / 2), _chartMargin + _chartCavanHeight, _xLabelWidth, _chartMargin)]; 113 PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(2 * _chartMargin + (index * _xLabelWidth) - (_xLabelWidth / 2), _chartMargin + _chartCavanHeight, _xLabelWidth, _chartMargin)];
111 [label setTextAlignment:NSTextAlignmentCenter]; 114 [label setTextAlignment:NSTextAlignmentCenter];
112 label.text = labelText; 115 label.text = labelText;
  116 + [self setCustomStyleForXLabel:label];
113 [self addSubview:label]; 117 [self addSubview:label];
114 } 118 }
115 } 119 }
@@ -118,6 +122,24 @@ @@ -118,6 +122,24 @@
118 } 122 }
119 } 123 }
120 124
  125 +- (void)setCustomStyleForXLabel:(UILabel *)label {
  126 + if (_xLabelFont) {
  127 + label.font = _xLabelFont;
  128 + }
  129 + if (_xLabelColor) {
  130 + label.textColor = _xLabelColor;
  131 + }
  132 +}
  133 +
  134 +- (void)setCustomStyleForYLabel:(UILabel *)label {
  135 + if (_yLabelFont) {
  136 + label.font = _yLabelFont;
  137 + }
  138 + if (_yLabelColor) {
  139 + label.textColor = _yLabelColor;
  140 + }
  141 +}
  142 +
121 143
122 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 144 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
123 { 145 {
@@ -7,4 +7,4 @@ DEPENDENCIES: @@ -7,4 +7,4 @@ DEPENDENCIES:
7 SPEC CHECKSUMS: 7 SPEC CHECKSUMS:
8 UICountingLabel: 0a0e9e34bf4690dbd127aaec552d19ed938087a9 8 UICountingLabel: 0a0e9e34bf4690dbd127aaec552d19ed938087a9
9 9
10 -COCOAPODS: 0.32.1 10 +COCOAPODS: 0.33.1