Merge pull request #101 from Antoine4011/custom-style
Label improvements
Showing
2 changed files
with
10 additions
and
7 deletions
| @@ -18,10 +18,12 @@ | @@ -18,10 +18,12 @@ | ||
| 18 | if (self) { | 18 | if (self) { |
| 19 | // Initialization code | 19 | // Initialization code |
| 20 | 20 | ||
| 21 | - [self setFont:[UIFont boldSystemFontOfSize:11.0f]]; | 21 | + self.font = [UIFont boldSystemFontOfSize:11.0f]; |
| 22 | self.backgroundColor = [UIColor clearColor]; | 22 | self.backgroundColor = [UIColor clearColor]; |
| 23 | - [self setTextAlignment:NSTextAlignmentCenter]; | 23 | + self.textAlignment = NSTextAlignmentCenter; |
| 24 | self.userInteractionEnabled = YES; | 24 | self.userInteractionEnabled = YES; |
| 25 | + self.minimumScaleFactor = 0.8; | ||
| 26 | + self.adjustsFontSizeToFitWidth = YES; | ||
| 25 | } | 27 | } |
| 26 | 28 | ||
| 27 | return self; | 29 | return self; |
| @@ -65,17 +65,17 @@ | @@ -65,17 +65,17 @@ | ||
| 65 | NSString *yLabelFormat = self.yLabelFormat ? : @"%1.f"; | 65 | NSString *yLabelFormat = self.yLabelFormat ? : @"%1.f"; |
| 66 | 66 | ||
| 67 | if (yStep == 0.0) { | 67 | if (yStep == 0.0) { |
| 68 | - PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight, _chartMargin, _yLabelHeight)]; | 68 | + PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (NSInteger)_chartCavanHeight, (NSInteger)_chartMargin, (NSInteger)_yLabelHeight)]; |
| 69 | minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0]; | 69 | minLabel.text = [NSString stringWithFormat:yLabelFormat, 0.0]; |
| 70 | [self setCustomStyleForYLabel:minLabel]; | 70 | [self setCustomStyleForYLabel:minLabel]; |
| 71 | [self addSubview:minLabel]; | 71 | [self addSubview:minLabel]; |
| 72 | 72 | ||
| 73 | - PNChartLabel *midLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, _chartCavanHeight / 2, _chartMargin, _yLabelHeight)]; | 73 | + PNChartLabel *midLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (NSInteger)(_chartCavanHeight / 2), (NSInteger)_chartMargin, (NSInteger)_yLabelHeight)]; |
| 74 | midLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax]; | 74 | midLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax]; |
| 75 | [self setCustomStyleForYLabel:midLabel]; | 75 | [self setCustomStyleForYLabel:midLabel]; |
| 76 | [self addSubview:midLabel]; | 76 | [self addSubview:midLabel]; |
| 77 | 77 | ||
| 78 | - PNChartLabel *maxLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, _chartMargin, _yLabelHeight)]; | 78 | + PNChartLabel *maxLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, (NSInteger)_chartMargin, (NSInteger)_yLabelHeight)]; |
| 79 | maxLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax * 2]; | 79 | maxLabel.text = [NSString stringWithFormat:yLabelFormat, _yValueMax * 2]; |
| 80 | [self setCustomStyleForYLabel:maxLabel]; | 80 | [self setCustomStyleForYLabel:maxLabel]; |
| 81 | [self addSubview:maxLabel]; | 81 | [self addSubview:maxLabel]; |
| @@ -86,7 +86,7 @@ | @@ -86,7 +86,7 @@ | ||
| 86 | 86 | ||
| 87 | while (num > 0) | 87 | while (num > 0) |
| 88 | { | 88 | { |
| 89 | - PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (_chartCavanHeight - index * yStepHeight), _chartMargin, _yLabelHeight)]; | 89 | + PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (NSInteger)(_chartCavanHeight - index * yStepHeight), (NSInteger)_chartMargin, (NSInteger)_yLabelHeight)]; |
| 90 | [label setTextAlignment:NSTextAlignmentRight]; | 90 | [label setTextAlignment:NSTextAlignmentRight]; |
| 91 | label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)]; | 91 | label.text = [NSString stringWithFormat:yLabelFormat, _yValueMin + (yStep * index)]; |
| 92 | [self setCustomStyleForYLabel:label]; | 92 | [self setCustomStyleForYLabel:label]; |
| @@ -124,7 +124,7 @@ | @@ -124,7 +124,7 @@ | ||
| 124 | NSInteger x = 2 * _chartMargin + (index * _xLabelWidth) - (_xLabelWidth / 2); | 124 | NSInteger x = 2 * _chartMargin + (index * _xLabelWidth) - (_xLabelWidth / 2); |
| 125 | NSInteger y = _chartMargin + _chartCavanHeight; | 125 | NSInteger y = _chartMargin + _chartCavanHeight; |
| 126 | 126 | ||
| 127 | - PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(x, y, _xLabelWidth, _chartMargin)]; | 127 | + PNChartLabel *label = [[PNChartLabel alloc] initWithFrame:CGRectMake(x, y, (NSInteger)_xLabelWidth, (NSInteger)_chartMargin)]; |
| 128 | [label setTextAlignment:NSTextAlignmentCenter]; | 128 | [label setTextAlignment:NSTextAlignmentCenter]; |
| 129 | label.text = labelText; | 129 | label.text = labelText; |
| 130 | [self setCustomStyleForXLabel:label]; | 130 | [self setCustomStyleForXLabel:label]; |
| @@ -142,6 +142,7 @@ | @@ -142,6 +142,7 @@ | ||
| 142 | if (_xLabelColor) { | 142 | if (_xLabelColor) { |
| 143 | label.textColor = _xLabelColor; | 143 | label.textColor = _xLabelColor; |
| 144 | } | 144 | } |
| 145 | + | ||
| 145 | } | 146 | } |
| 146 | 147 | ||
| 147 | - (void)setCustomStyleForYLabel:(UILabel *)label | 148 | - (void)setCustomStyleForYLabel:(UILabel *)label |
-
Please register or login to post a comment