Skip to content

Commit

Permalink
Merge pull request #2 from front9tech/master
Browse files Browse the repository at this point in the history
Added the optional parameter to specify a font name. Thanks front9tech for your contribution!
  • Loading branch information
hugo53 committed Oct 25, 2014
2 parents 25f6169 + 8db669b commit 8741a43
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions HUChart/HUSemiCircleChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ typedef enum showTextType
@property (nonatomic) NSString *title; // Chart title
@property (nonatomic) ShowTextType showPortionTextType; // Show text/value/nothing for each portion. Default=SHOW_PORTION_TEXT
@property (assign) BOOL showChartTitle; // Show chart title (Default:YES)
@property (nonatomic) NSString *fontName; // Name of the font you would like to use (Optional)

@end
28 changes: 25 additions & 3 deletions HUChart/HUSemiCircleChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @implementation HUSemiCircleChart
@synthesize title;
@synthesize showChartTitle;
@synthesize showPortionTextType;
@synthesize fontName;

-(id) init{
self = [super init];
Expand Down Expand Up @@ -137,7 +138,14 @@ -(void) drawRect:(CGRect)rect{

// Draw title if it is set
if (self.showChartTitle) {
UIFont *font = [UIFont boldSystemFontOfSize:r/4];
UIFont *font = nil;

if (fontName) {
font = [UIFont fontWithName:fontName size:r/4];
} else {
font = [UIFont boldSystemFontOfSize:r/4];
}

[self drawText:self.title
withFont:font withColor:[UIColor blackColor]
inContext:context inRect:CGRectMake(R-r*sqrt(3)/2,
Expand Down Expand Up @@ -227,7 +235,13 @@ - (void)drawPortionValue:(id) portionValue inContext:(CGContextRef)context
origin:(CGPoint)origin R:(float)R r:(float)r
startAngle:(float)startAngle endAngle:(float)endAngle {

UIFont *font = [UIFont boldSystemFontOfSize:r/4];
UIFont *font = nil;
if (fontName) {
font = [UIFont fontWithName:fontName size:r/4];
} else {
font = [UIFont boldSystemFontOfSize:r/4];
}


NSString *portionValueText;
if ([portionValue isKindOfClass:[NSNumber class]]) {
Expand Down Expand Up @@ -266,7 +280,15 @@ - (BOOL)isDrawable:(CGRect)rect {
if (rect.size.height < rect.size.width/2.0) {
[[UIColor yellowColor]set];
UIRectFill([self bounds]);
UIFont *font = [UIFont boldSystemFontOfSize:MIN(rect.size.width/25.0, 12)];

UIFont *font = nil;
if (fontName) {
font = [UIFont fontWithName:fontName size:MIN(rect.size.width/25.0, 12)];
} else {
font = [UIFont boldSystemFontOfSize:MIN(rect.size.width/25.0, 12)];
}


[self drawText: @"Cannot draw because rect height is too small."
@"\nPlease sure that rect height >= rect width/2"
withFont:font withColor:[UIColor blackColor]
Expand Down

0 comments on commit 8741a43

Please sign in to comment.