Move code from setXLabels: to setStroke:
Now you can use showLabels, setXLabels, etc in different order.
Showing
2 changed files
with
20 additions
and
15 deletions
| @@ -66,35 +66,38 @@ | @@ -66,35 +66,38 @@ | ||
| 66 | 66 | ||
| 67 | -(void)setXLabels:(NSArray *)xLabels | 67 | -(void)setXLabels:(NSArray *)xLabels |
| 68 | { | 68 | { |
| 69 | - [self viewCleanupForCollection:_labels]; | ||
| 70 | _xLabels = xLabels; | 69 | _xLabels = xLabels; |
| 71 | 70 | ||
| 72 | if (_showLabel) { | 71 | if (_showLabel) { |
| 73 | _xLabelWidth = (self.frame.size.width - chartMargin*2)/[xLabels count]; | 72 | _xLabelWidth = (self.frame.size.width - chartMargin*2)/[xLabels count]; |
| 74 | - | ||
| 75 | - for(int index = 0; index < xLabels.count; index++) | ||
| 76 | - { | ||
| 77 | - NSString* labelText = xLabels[index]; | ||
| 78 | - PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin), self.frame.size.height - 30.0, _xLabelWidth, 20.0)]; | ||
| 79 | - [label setTextAlignment:NSTextAlignmentCenter]; | ||
| 80 | - label.text = labelText; | ||
| 81 | - [_labels addObject:label]; | ||
| 82 | - [self addSubview:label]; | ||
| 83 | - } | ||
| 84 | } | 73 | } |
| 85 | } | 74 | } |
| 86 | 75 | ||
| 87 | -(void)setStrokeColor:(UIColor *)strokeColor | 76 | -(void)setStrokeColor:(UIColor *)strokeColor |
| 88 | { | 77 | { |
| 89 | - _strokeColor = strokeColor; | 78 | + _strokeColor = strokeColor; |
| 90 | } | 79 | } |
| 91 | 80 | ||
| 92 | -(void)strokeChart | 81 | -(void)strokeChart |
| 93 | { | 82 | { |
| 83 | + [self viewCleanupForCollection:_labels]; | ||
| 84 | + | ||
| 85 | + for(int index = 0; index < _xLabels.count; index++) | ||
| 86 | + { | ||
| 87 | + NSString* labelText = _xLabels[index]; | ||
| 88 | + PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin), self.frame.size.height - 30.0, _xLabelWidth, 20.0)]; | ||
| 89 | + [label setTextAlignment:NSTextAlignmentCenter]; | ||
| 90 | + label.text = labelText; | ||
| 91 | + [_labels addObject:label]; | ||
| 92 | + [self addSubview:label]; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + | ||
| 94 | [self viewCleanupForCollection:_bars]; | 96 | [self viewCleanupForCollection:_bars]; |
| 97 | + | ||
| 95 | CGFloat chartCavanHeight = self.frame.size.height - chartMargin * 2 - 40.0; | 98 | CGFloat chartCavanHeight = self.frame.size.height - chartMargin * 2 - 40.0; |
| 96 | NSInteger index = 0; | 99 | NSInteger index = 0; |
| 97 | - | 100 | + |
| 98 | for (NSString * valueString in _yValues) { | 101 | for (NSString * valueString in _yValues) { |
| 99 | float value = [valueString floatValue]; | 102 | float value = [valueString floatValue]; |
| 100 | 103 | ||
| @@ -102,7 +105,9 @@ | @@ -102,7 +105,9 @@ | ||
| 102 | PNBar * bar; | 105 | PNBar * bar; |
| 103 | if (_showLabel) { | 106 | if (_showLabel) { |
| 104 | bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight - 30.0, _xLabelWidth * 0.5, chartCavanHeight)]; | 107 | bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight - 30.0, _xLabelWidth * 0.5, chartCavanHeight)]; |
| 105 | - }else{ | 108 | + |
| 109 | + } | ||
| 110 | + else{ | ||
| 106 | bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight , _xLabelWidth * 0.6, chartCavanHeight)]; | 111 | bar = [[PNBar alloc] initWithFrame:CGRectMake((index * _xLabelWidth + chartMargin + _xLabelWidth * 0.25), self.frame.size.height - chartCavanHeight , _xLabelWidth * 0.6, chartCavanHeight)]; |
| 107 | } | 112 | } |
| 108 | bar.backgroundColor = _barBackgroundColor; | 113 | bar.backgroundColor = _barBackgroundColor; |
-
Please register or login to post a comment