Permalink
Browse files

Add option to outline the percentage text.

  • Loading branch information...
1 parent e3bf596 commit 03ba9146dc93ae62ef693c6083fc1db2c7ab000b @lxcid committed Mar 1, 2012
Showing with 33 additions and 2 deletions.
  1. +2 −0 iOSPlot/Shared/PCPieChart.h
  2. +31 −2 iOSPlot/Shared/PCPieChart.m
@@ -62,10 +62,12 @@
int diameter;
UIFont *titleFont, *percentageFont;
BOOL showArrow, sameColorLabel;
+ BOOL outline;
}
@property (nonatomic, assign) int diameter;
@property (nonatomic, retain) NSMutableArray *components;
@property (nonatomic, retain) UIFont *titleFont, *percentageFont;
@property (nonatomic, assign) BOOL showArrow, sameColorLabel;
+@property (nonatomic, assign, getter = hasOutline) BOOL outline;
@end
@@ -75,6 +75,7 @@ @implementation PCPieChart
@synthesize diameter;
@synthesize titleFont, percentageFont;
@synthesize showArrow, sameColorLabel;
+@synthesize outline = _outline;
- (id)initWithFrame:(CGRect)frame
{
@@ -209,7 +210,21 @@ - (void)drawRect:(CGRect)rect
NSString *percentageText = [NSString stringWithFormat:@"%.1f%%", component.value/total*100];
CGSize optimumSize = [percentageText sizeWithFont:self.percentageFont constrainedToSize:CGSizeMake(max_text_width,100)];
CGRect percFrame = CGRectMake(5, left_label_y, max_text_width, optimumSize.height);
- [percentageText drawInRect:percFrame withFont:self.percentageFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight];
+
+ if (self.hasOutline) {
+ CGContextSaveGState(ctx);
+
+ CGContextSetLineWidth(ctx, 1.0f);
+ CGContextSetLineJoin(ctx, kCGLineJoinRound);
+ CGContextSetTextDrawingMode (ctx, kCGTextFillStroke);
+ CGContextSetRGBStrokeColor(ctx, 0.2f, 0.2f, 0.2f, 0.8f);
+
+ [percentageText drawInRect:percFrame withFont:self.percentageFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight];
+
+ CGContextRestoreGState(ctx);
+ } else {
+ [percentageText drawInRect:percFrame withFont:self.percentageFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight];
+ }
if (self.showArrow)
{
@@ -343,7 +358,21 @@ - (void)drawRect:(CGRect)rect
NSString *percentageText = [NSString stringWithFormat:@"%.1f%%", component.value/total*100];
CGSize optimumSize = [percentageText sizeWithFont:self.percentageFont constrainedToSize:CGSizeMake(max_text_width,100)];
CGRect percFrame = CGRectMake(text_x, right_label_y, optimumSize.width, optimumSize.height);
- [percentageText drawInRect:percFrame withFont:self.percentageFont];
+
+ if (self.hasOutline) {
+ CGContextSaveGState(ctx);
+
+ CGContextSetLineWidth(ctx, 1.0f);
+ CGContextSetLineJoin(ctx, kCGLineJoinRound);
+ CGContextSetTextDrawingMode (ctx, kCGTextFillStroke);
+ CGContextSetRGBStrokeColor(ctx, 0.2f, 0.2f, 0.2f, 0.8f);
+
+ [percentageText drawInRect:percFrame withFont:self.percentageFont];
+
+ CGContextRestoreGState(ctx);
+ } else {
+ [percentageText drawInRect:percFrame withFont:self.percentageFont];
+ }
if (self.showArrow)
{

0 comments on commit 03ba914

Please sign in to comment.