Today's Menu  Portugal
journal and plan nutrition
Functions
ZCMCommon.m File Reference
#import "ZCMCommon.h"
#import <UIKit/UIKit.h>
Include dependency graph for ZCMCommon.m:

Go to the source code of this file.

Functions

void drawLinearGradient (CGContextRef context, CGRect rect, CGColorRef startColor, CGColorRef endColor)
 
CGRect rectFor1PxStroke (CGRect rect)
 
void draw1PxStroke (CGContextRef context, CGPoint startPoint, CGPoint endPoint, CGColorRef color)
 
void drawGlossAndGradient (CGContextRef context, CGRect rect, CGColorRef startColor, CGColorRef endColor)
 
CGMutablePathRef createArcPathFromBottomOfRect (CGRect rect, CGFloat arcHeight)
 

Function Documentation

◆ createArcPathFromBottomOfRect()

CGMutablePathRef createArcPathFromBottomOfRect ( CGRect  rect,
CGFloat  arcHeight 
)

Definition at line 64 of file ZCMCommon.m.

65 {
66  CGRect arcRect = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height - arcHeight, rect.size.width, arcHeight);
67 
68  CGFloat arcRadius = (arcRect.size.height/2) + (pow(arcRect.size.width, 2) / (8*arcRect.size.height));
69  CGPoint arcCenter = CGPointMake(arcRect.origin.x + arcRect.size.width/2, arcRect.origin.y + arcRadius);
70 
71  CGFloat angle = acos(arcRect.size.width / (2*arcRadius));
72  CGFloat startAngle = radians(180) + angle;
73  CGFloat endAngle = radians(360) - angle;
74 
75  CGMutablePathRef path = CGPathCreateMutable();
76  CGPathAddArc(path, NULL, arcCenter.x, arcCenter.y, arcRadius, startAngle, endAngle, 0);
77  CGPathAddLineToPoint(path, NULL, CGRectGetMaxX(rect), CGRectGetMinY(rect));
78  CGPathAddLineToPoint(path, NULL, CGRectGetMinX(rect), CGRectGetMinY(rect));
79  CGPathAddLineToPoint(path, NULL, CGRectGetMinX(rect), CGRectGetMaxY(rect));
80 
81  return path;
82 }
static double radians(double degrees)
Definition: ZCMCommon.h:16

◆ draw1PxStroke()

void draw1PxStroke ( CGContextRef  context,
CGPoint  startPoint,
CGPoint  endPoint,
CGColorRef  color 
)

Definition at line 40 of file ZCMCommon.m.

41 {
42  CGContextSaveGState(context);
43  CGContextSetLineCap(context, kCGLineCapSquare);
44  CGContextSetStrokeColorWithColor(context, color);
45  CGContextSetLineWidth(context, 1.0);
46  CGContextMoveToPoint(context, startPoint.x + 0.5, startPoint.y + 0.5);
47  CGContextAddLineToPoint(context, endPoint.x + 0.5, endPoint.y + 0.5);
48  CGContextStrokePath(context);
49  CGContextRestoreGState(context);
50 }

◆ drawGlossAndGradient()

void drawGlossAndGradient ( CGContextRef  context,
CGRect  rect,
CGColorRef  startColor,
CGColorRef  endColor 
)

Definition at line 52 of file ZCMCommon.m.

53 {
54  drawLinearGradient(context, rect, startColor, endColor);
55 
56  UIColor * glossColor1 = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.35];
57  UIColor * glossColor2 = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.1];
58 
59  CGRect topHalf = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height/2);
60 
61  drawLinearGradient(context, topHalf, glossColor1.CGColor, glossColor2.CGColor);
62 }
void drawLinearGradient(CGContextRef context, CGRect rect, CGColorRef startColor, CGColorRef endColor)
Definition: ZCMCommon.m:12

◆ drawLinearGradient()

void drawLinearGradient ( CGContextRef  context,
CGRect  rect,
CGColorRef  startColor,
CGColorRef  endColor 
)

Definition at line 12 of file ZCMCommon.m.

13 {
14  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
15  CGFloat locations[] = { 0.0, 1.0 };
16 
17  NSArray *colors = @[(__bridge id) startColor, (__bridge id) endColor];
18 
19  CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
20 
21  CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
22  CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
23 
24  CGContextSaveGState(context);
25  CGContextAddRect(context, rect);
26  CGContextClip(context);
27  CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
28  CGContextRestoreGState(context);
29 
30  CGGradientRelease(gradient);
31  CGColorSpaceRelease(colorSpace);
32 
33 }

◆ rectFor1PxStroke()

CGRect rectFor1PxStroke ( CGRect  rect)

Definition at line 35 of file ZCMCommon.m.

36 {
37  return CGRectMake(rect.origin.x + 0.5, rect.origin.y + 0.5, rect.size.width - 1, rect.size.height - 1);
38 }