Permalink
Browse files

Add options to adjust label color and shadow for better contrast.

  • Loading branch information...
1 parent 37ed579 commit c620042e97ce3fea6c4370184a86460f796fd139 @nschum nschum committed Sep 14, 2012
Showing with 20 additions and 3 deletions.
  1. +4 −2 Demo/XYPieChart/ViewController.m
  2. +2 −0 Demo/XYPieChart/XYPieChart.h
  3. +12 −1 Demo/XYPieChart/XYPieChart.m
  4. +2 −0 README.textile
@@ -49,12 +49,14 @@ - (void)viewDidLoad
[self.pieChartLeft setPieBackgroundColor:[UIColor colorWithWhite:0.95 alpha:1]];
[self.pieChartLeft setPieCenter:CGPointMake(240, 240)];
[self.pieChartLeft setUserInteractionEnabled:NO];
-
+ [self.pieChartLeft setLabelShadowColor:[UIColor blackColor]];
+
[self.pieChartRight setDelegate:self];
[self.pieChartRight setDataSource:self];
[self.pieChartRight setPieCenter:CGPointMake(240, 240)];
[self.pieChartRight setShowPercentage:NO];
-
+ [self.pieChartRight setLabelColor:[UIColor blackColor]];
+
[self.percentageLabel.layer setCornerRadius:90];
self.sliceColors =[NSArray arrayWithObjects:
@@ -54,6 +54,8 @@
@property(nonatomic, assign) CGFloat pieRadius;
@property(nonatomic, assign) BOOL showLabel;
@property(nonatomic, strong) UIFont *labelFont;
+@property(nonatomic, strong) UIColor *labelColor;
+@property(nonatomic, strong) UIColor *labelShadowColor;
@property(nonatomic, assign) CGFloat labelRadius;
@property(nonatomic, assign) CGFloat selectedSliceStroke;
@property(nonatomic, assign) CGFloat selectedSliceOffsetRadius;
@@ -111,6 +111,8 @@ @implementation XYPieChart
@synthesize pieRadius = _pieRadius;
@synthesize showLabel = _showLabel;
@synthesize labelFont = _labelFont;
+@synthesize labelColor = _labelColor;
+@synthesize labelShadowColor = _labelShadowColor;
@synthesize labelRadius = _labelRadius;
@synthesize selectedSliceStroke = _selectedSliceStroke;
@synthesize selectedSliceOffsetRadius = _selectedSliceOffsetRadius;
@@ -147,6 +149,7 @@ - (id)initWithFrame:(CGRect)frame
self.pieRadius = MIN(frame.size.width/2, frame.size.height/2) - 10;
self.pieCenter = CGPointMake(frame.size.width/2, frame.size.height/2);
self.labelFont = [UIFont boldSystemFontOfSize:MAX((int)self.pieRadius/10, 5)];
+ _labelColor = [UIColor whiteColor];
_labelRadius = _pieRadius/2;
_selectedSliceOffsetRadius = MAX(10, _pieRadius/10);
@@ -187,6 +190,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder
self.pieRadius = MIN(bounds.size.width/2, bounds.size.height/2) - 10;
self.pieCenter = CGPointMake(bounds.size.width/2, bounds.size.height/2);
self.labelFont = [UIFont boldSystemFontOfSize:MAX((int)self.pieRadius/10, 5)];
+ _labelColor = [UIColor whiteColor];
_labelRadius = _pieRadius/2;
_selectedSliceOffsetRadius = MAX(10, _pieRadius/10);
@@ -584,7 +588,7 @@ - (void)notifyDelegateOfSelectionChangeFrom:(NSUInteger)previousSelection to:(NS
{
SliceLayer *layer = [_pieView.layer.sublayers objectAtIndex:newSelection];
if(_selectedSliceOffsetRadius > 0 && layer){
-
+
if (layer.isSelected) {
if ([_delegate respondsToSelector:@selector(pieChart:willDeselectSliceAtIndex:)])
[_delegate pieChart:self willDeselectSliceAtIndex:newSelection];
@@ -618,6 +622,13 @@ - (SliceLayer *)createSliceLayer
[textLayer setAnchorPoint:CGPointMake(0.5, 0.5)];
[textLayer setAlignmentMode:kCAAlignmentCenter];
[textLayer setBackgroundColor:[UIColor clearColor].CGColor];
+ [textLayer setForegroundColor:self.labelColor.CGColor];
+ if (self.labelShadowColor) {
+ [textLayer setShadowColor:self.labelShadowColor.CGColor];
+ [textLayer setShadowOffset:CGSizeZero];
+ [textLayer setShadowOpacity:1.0f];
+ [textLayer setShadowRadius:2.0f];
+ }
CGSize size = [@"0" sizeWithFont:self.labelFont];
[CATransaction setDisableActions:YES];
[textLayer setFrame:CGRectMake(0, 0, size.width, size.height)];
View
@@ -34,6 +34,8 @@ Set PieChart properties:
[self.pieChart setStartPieAngle:M_PI_2]; //optional
[self.pieChart setAnimationSpeed:1.0]; //optional
[self.pieChart setLabelFont:[UIFont fontWithName:@"DBLCDTempBlack" size:24]]; //optional
+[self.pieChart setLabelColor:[UIColor blackColor]]; //optional, defaults to white
+[self.pieChart setLabelShadowColor:[UIColor blackColor]]; //optional, defaults to none (nil)
[self.pieChart setLabelRadius:160]; //optional
[self.pieChart setShowPercentage:YES]; //optional
[self.pieChart setPieBackgroundColor:[UIColor colorWithWhite:0.95 alpha:1]]; //optional

0 comments on commit c620042

Please sign in to comment.