Created
March 28, 2012 14:52
-
-
Save leearmstrong/2226821 to your computer and use it in GitHub Desktop.
Draws a circle with a number in the middle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// Abstracted Graphic Attributes | |
NSString* textContent = [NSString stringWithFormat:@"%i",[myAnnotation.annotations count]]; | |
//// General Declarations | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
//// Gradient Declarations | |
NSArray* gradient3Colors = [NSArray arrayWithObjects: | |
(id)[UIColor lightGrayColor].CGColor, | |
(id)[UIColor darkGrayColor].CGColor, nil]; | |
CGFloat gradient3Locations[] = {0, 1}; | |
CGGradientRef gradient3 = CGGradientCreateWithColors(colorSpace, (CFArrayRef)gradient3Colors, gradient3Locations); | |
//// Oval Drawing | |
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0.5, 0.5, 34, 34)]; | |
CGContextSaveGState(context); | |
[ovalPath addClip]; | |
CGContextDrawRadialGradient(context, gradient3, | |
CGPointMake(17.5, 17.5), 10, | |
CGPointMake(17.5, 17.5), 30, | |
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation); | |
CGContextRestoreGState(context); | |
[[UIColor blackColor] setStroke]; | |
ovalPath.lineWidth = 0.5; | |
[ovalPath stroke]; | |
//// Text Drawing | |
CGRect textFrame = CGRectMake(0, 7.0, 35, 20); | |
[[UIColor whiteColor] setFill]; | |
[textContent drawInRect: textFrame withFont: [UIFont fontWithName: @"HelveticaNeue" size: [UIFont systemFontSize]] lineBreakMode: UILineBreakModeWordWrap alignment: UITextAlignmentCenter]; | |
//// Cleanup | |
CGGradientRelease(gradient3); | |
CGColorSpaceRelease(colorSpace); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment