Showing
2 changed files
with
32 additions
and
3 deletions
| @@ -46,6 +46,9 @@ | @@ -46,6 +46,9 @@ | ||
| 46 | 46 | ||
| 47 | @property (nonatomic, weak) id<PNChartDelegate> delegate; | 47 | @property (nonatomic, weak) id<PNChartDelegate> delegate; |
| 48 | 48 | ||
| 49 | +/** Multiple selection */ | ||
| 50 | +@property (nonatomic, assign) BOOL enableMultipleSelection; | ||
| 51 | + | ||
| 49 | - (void)strokeChart; | 52 | - (void)strokeChart; |
| 50 | 53 | ||
| 51 | @end | 54 | @end |
| @@ -23,6 +23,8 @@ | @@ -23,6 +23,8 @@ | ||
| 23 | @property (nonatomic) NSMutableArray *descriptionLabels; | 23 | @property (nonatomic) NSMutableArray *descriptionLabels; |
| 24 | @property (strong, nonatomic) CAShapeLayer *sectorHighlight; | 24 | @property (strong, nonatomic) CAShapeLayer *sectorHighlight; |
| 25 | 25 | ||
| 26 | +@property (nonatomic, strong) NSMutableDictionary *selectedItems; | ||
| 27 | + | ||
| 26 | - (void)loadDefault; | 28 | - (void)loadDefault; |
| 27 | 29 | ||
| 28 | - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index; | 30 | - (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index; |
| @@ -48,6 +50,7 @@ | @@ -48,6 +50,7 @@ | ||
| 48 | self = [self initWithFrame:frame]; | 50 | self = [self initWithFrame:frame]; |
| 49 | if(self){ | 51 | if(self){ |
| 50 | _items = [NSArray arrayWithArray:items]; | 52 | _items = [NSArray arrayWithArray:items]; |
| 53 | + _selectedItems = [NSMutableDictionary dictionary]; | ||
| 51 | _outerCircleRadius = CGRectGetWidth(self.bounds) / 2; | 54 | _outerCircleRadius = CGRectGetWidth(self.bounds) / 2; |
| 52 | _innerCircleRadius = CGRectGetWidth(self.bounds) / 6; | 55 | _innerCircleRadius = CGRectGetWidth(self.bounds) / 6; |
| 53 | 56 | ||
| @@ -57,6 +60,7 @@ | @@ -57,6 +60,7 @@ | ||
| 57 | _descriptionTextShadowOffset = CGSizeMake(0, 1); | 60 | _descriptionTextShadowOffset = CGSizeMake(0, 1); |
| 58 | _duration = 1.0; | 61 | _duration = 1.0; |
| 59 | _shouldHighlightSectorOnTouch = YES; | 62 | _shouldHighlightSectorOnTouch = YES; |
| 63 | + _enableMultipleSelection = NO; | ||
| 60 | 64 | ||
| 61 | [super setupDefaultValues]; | 65 | [super setupDefaultValues]; |
| 62 | [self loadDefault]; | 66 | [self loadDefault]; |
| @@ -284,9 +288,11 @@ | @@ -284,9 +288,11 @@ | ||
| 284 | [self.delegate userClickedOnPieIndexItem:index]; | 288 | [self.delegate userClickedOnPieIndexItem:index]; |
| 285 | } | 289 | } |
| 286 | 290 | ||
| 287 | - if (self.shouldHighlightSectorOnTouch) { | 291 | + if (self.shouldHighlightSectorOnTouch) |
| 288 | - | 292 | + { |
| 289 | - if (self.sectorHighlight) { | 293 | + if (!self.enableMultipleSelection) |
| 294 | + { | ||
| 295 | + if (self.sectorHighlight) | ||
| 290 | [self.sectorHighlight removeFromSuperlayer]; | 296 | [self.sectorHighlight removeFromSuperlayer]; |
| 291 | } | 297 | } |
| 292 | 298 | ||
| @@ -300,14 +306,34 @@ | @@ -300,14 +306,34 @@ | ||
| 300 | 306 | ||
| 301 | CGFloat startPercnetage = [self startPercentageForItemAtIndex:index]; | 307 | CGFloat startPercnetage = [self startPercentageForItemAtIndex:index]; |
| 302 | CGFloat endPercentage = [self endPercentageForItemAtIndex:index]; | 308 | CGFloat endPercentage = [self endPercentageForItemAtIndex:index]; |
| 309 | + | ||
| 303 | self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5 | 310 | self.sectorHighlight = [self newCircleLayerWithRadius:_outerCircleRadius + 5 |
| 304 | borderWidth:10 | 311 | borderWidth:10 |
| 305 | fillColor:[UIColor clearColor] | 312 | fillColor:[UIColor clearColor] |
| 306 | borderColor:newColor | 313 | borderColor:newColor |
| 307 | startPercentage:startPercnetage | 314 | startPercentage:startPercnetage |
| 308 | endPercentage:endPercentage]; | 315 | endPercentage:endPercentage]; |
| 316 | + | ||
| 317 | + if (self.enableMultipleSelection) | ||
| 318 | + { | ||
| 319 | + NSString *dictIndex = [NSString stringWithFormat:@"%d", index]; | ||
| 320 | + CAShapeLayer *indexShape = [self.selectedItems valueForKey:dictIndex]; | ||
| 321 | + if (indexShape) | ||
| 322 | + { | ||
| 323 | + [indexShape removeFromSuperlayer]; | ||
| 324 | + [self.selectedItems removeObjectForKey:dictIndex]; | ||
| 325 | + } | ||
| 326 | + else | ||
| 327 | + { | ||
| 328 | + [self.selectedItems setObject:self.sectorHighlight forKey:dictIndex]; | ||
| 309 | [_contentView.layer addSublayer:self.sectorHighlight]; | 329 | [_contentView.layer addSublayer:self.sectorHighlight]; |
| 310 | } | 330 | } |
| 331 | + } | ||
| 332 | + else | ||
| 333 | + { | ||
| 334 | + [_contentView.layer addSublayer:self.sectorHighlight]; | ||
| 335 | + } | ||
| 336 | + } | ||
| 311 | } | 337 | } |
| 312 | 338 | ||
| 313 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | 339 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event |
-
Please register or login to post a comment