Skip to content

Instantly share code, notes, and snippets.

@mario
Created July 8, 2015 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mario/ac6dcf9c7639afdf9193 to your computer and use it in GitHub Desktop.
Save mario/ac6dcf9c7639afdf9193 to your computer and use it in GitHub Desktop.
//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();
//// Color Declarations
UIColor* f65A52 = [UIColor colorWithRed: 1 green: 0 blue: 0 alpha: 1];
//// Bezier 2 Drawing
UIBezierPath* bezier2Path = UIBezierPath.bezierPath;
[bezier2Path moveToPoint: CGPointMake(45.9, 48.28)];
[bezier2Path addCurveToPoint: CGPointMake(45.9, 131.72) controlPoint1: CGPointMake(12.7, 71.32) controlPoint2: CGPointMake(12.7, 108.68)];
[bezier2Path addCurveToPoint: CGPointMake(122.32, 147.91) controlPoint1: CGPointMake(66.66, 146.13) controlPoint2: CGPointMake(95.5, 151.53)];
[bezier2Path addCurveToPoint: CGPointMake(168.5, 169.5) controlPoint1: CGPointMake(140.44, 159.66) controlPoint2: CGPointMake(168.5, 169.5)];
[bezier2Path addCurveToPoint: CGPointMake(153.67, 138.86) controlPoint1: CGPointMake(168.5, 169.5) controlPoint2: CGPointMake(158.84, 153.11)];
[bezier2Path addCurveToPoint: CGPointMake(166.1, 131.72) controlPoint1: CGPointMake(158.05, 136.8) controlPoint2: CGPointMake(162.22, 134.42)];
[bezier2Path addCurveToPoint: CGPointMake(166.1, 48.28) controlPoint1: CGPointMake(199.3, 108.68) controlPoint2: CGPointMake(199.3, 71.32)];
[bezier2Path addCurveToPoint: CGPointMake(45.9, 48.28) controlPoint1: CGPointMake(132.91, 25.24) controlPoint2: CGPointMake(79.09, 25.24)];
[bezier2Path closePath];
[f65A52 setFill];
[bezier2Path fill];
[f65A52 setStroke];
bezier2Path.lineWidth = 9;
[bezier2Path stroke];
//// Text Drawing
CGRect textRect = CGRectMake(52, 56, 108, 67);
{
NSString* textContent = @"Hello, World!";
NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy;
textStyle.alignment = NSTextAlignmentLeft;
NSDictionary* textFontAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize: UIFont.labelFontSize], NSForegroundColorAttributeName: UIColor.blackColor, NSParagraphStyleAttributeName: textStyle};
CGFloat textTextHeight = [textContent boundingRectWithSize: CGSizeMake(textRect.size.width, INFINITY) options: NSStringDrawingUsesLineFragmentOrigin attributes: textFontAttributes context: nil].size.height;
CGContextSaveGState(context);
CGContextClipToRect(context, textRect);
[textContent drawInRect: CGRectMake(CGRectGetMinX(textRect), CGRectGetMinY(textRect) + (CGRectGetHeight(textRect) - textTextHeight) / 2, CGRectGetWidth(textRect), textTextHeight) withAttributes: textFontAttributes];
CGContextRestoreGState(context);
}
@mario
Copy link
Author

mario commented Jul 8, 2015

//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();

//// Color Declarations
UIColor* f65A52 = [UIColor colorWithRed: 1 green: 0 blue: 0 alpha: 1];

//// Bezier 2 Drawing
UIBezierPath* bezier2Path = UIBezierPath.bezierPath;
[bezier2Path moveToPoint: CGPointMake(166.1, 48.28)];
[bezier2Path addCurveToPoint: CGPointMake(166.1, 131.72) controlPoint1: CGPointMake(199.3, 71.32) controlPoint2: CGPointMake(199.3, 108.68)];
[bezier2Path addCurveToPoint: CGPointMake(89.68, 147.91) controlPoint1: CGPointMake(145.34, 146.13) controlPoint2: CGPointMake(116.5, 151.53)];
[bezier2Path addCurveToPoint: CGPointMake(43.5, 169.5) controlPoint1: CGPointMake(71.56, 159.66) controlPoint2: CGPointMake(43.5, 169.5)];
[bezier2Path addCurveToPoint: CGPointMake(58.33, 138.86) controlPoint1: CGPointMake(43.5, 169.5) controlPoint2: CGPointMake(53.16, 153.11)];
[bezier2Path addCurveToPoint: CGPointMake(45.9, 131.72) controlPoint1: CGPointMake(53.95, 136.8) controlPoint2: CGPointMake(49.78, 134.42)];
[bezier2Path addCurveToPoint: CGPointMake(45.9, 48.28) controlPoint1: CGPointMake(12.7, 108.68) controlPoint2: CGPointMake(12.7, 71.32)];
[bezier2Path addCurveToPoint: CGPointMake(166.1, 48.28) controlPoint1: CGPointMake(79.09, 25.24) controlPoint2: CGPointMake(132.91, 25.24)];
[bezier2Path closePath];
[f65A52 setFill];
[bezier2Path fill];
[f65A52 setStroke];
bezier2Path.lineWidth = 9;
[bezier2Path stroke];

//// Text Drawing
CGRect textRect = CGRectMake(52, 56, 108, 67);
{
NSString* textContent = @"Hello, World!";
NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy;
textStyle.alignment = NSTextAlignmentLeft;

NSDictionary* textFontAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize: UIFont.labelFontSize], NSForegroundColorAttributeName: UIColor.blackColor, NSParagraphStyleAttributeName: textStyle};

CGFloat textTextHeight = [textContent boundingRectWithSize: CGSizeMake(textRect.size.width, INFINITY)  options: NSStringDrawingUsesLineFragmentOrigin attributes: textFontAttributes context: nil].size.height;
CGContextSaveGState(context);
CGContextClipToRect(context, textRect);
[textContent drawInRect: CGRectMake(CGRectGetMinX(textRect), CGRectGetMinY(textRect) + (CGRectGetHeight(textRect) - textTextHeight) / 2, CGRectGetWidth(textRect), textTextHeight) withAttributes: textFontAttributes];
CGContextRestoreGState(context);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment