Skip to content

Instantly share code, notes, and snippets.

@dawand
Created August 10, 2015 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dawand/40f9b469b9bd598a3413 to your computer and use it in GitHub Desktop.
Save dawand/40f9b469b9bd598a3413 to your computer and use it in GitHub Desktop.
//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();
//// Color Declarations
UIColor *color = [UIColor colorWithRed:0.306 green:0.678 blue:0.604 alpha:1.0];
UIColor *shadowColor = [UIColor colorWithRed:0.20 green:0.200 blue:0.200 alpha:1.0];
NSShadow *shadow;
shadow.shadowColor = [shadowColor colorWithAlphaComponent:0.72];
shadow.shadowOffset = CGSizeMake(0.1, -0.1);
shadow.shadowBlurRadius = 5;
//// Rectangle Drawing
CGRect rectangleRect = CGRectMake(52, 35, 140, 37);
UIBezierPath *rectanglePath = [UIBezierPath bezierPathWithRoundedRect:rectangleRect cornerRadius:15];
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, shadow.shadowOffset, shadow.shadowBlurRadius, shadowColor.CGColor);
[color setFill];
[rectanglePath fill];
CGContextRestoreGState(context);
NSString *rectangleTextContent = @"Take a picture";
NSMutableParagraphStyle *rectangleStyle = (NSMutableParagraphStyle *)[[NSParagraphStyle defaultParagraphStyle]mutableCopy];
rectangleStyle.alignment=NSTextAlignmentCenter;
NSDictionary *rectangleFontAttributes = [[NSDictionary alloc] initWithObjectsAndKeys: [UIFont fontWithName:@"Range-SemiBold" size:15], NSFontAttributeName, [UIColor whiteColor], rectangleStyle, nil];
CGFloat rectangleTextHeight = ([rectangleTextContent boundingRectWithSize:CGSizeMake(rectangleRect.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:rectangleFontAttributes context:nil]).size.height;
CGContextSaveGState(context);
CGContextClipToRect(context, rectangleRect);
[rectangleTextContent drawInRect:CGRectMake(rectangleRect.origin.x, rectangleRect.origin.y + (rectangleRect.size.height - rectangleTextHeight) / 2, rectangleRect.size.width, rectangleTextHeight) withAttributes:rectangleFontAttributes];
CGContextRestoreGState(context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment