10 #import <UIKit/UIKit.h> 12 void drawLinearGradient(CGContextRef context, CGRect rect, CGColorRef startColor, CGColorRef endColor)
14 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
15 CGFloat locations[] = { 0.0, 1.0 };
17 NSArray *colors = @[(__bridge id) startColor, (__bridge id) endColor];
19 CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
21 CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
22 CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
24 CGContextSaveGState(context);
25 CGContextAddRect(context, rect);
26 CGContextClip(context);
27 CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
28 CGContextRestoreGState(context);
30 CGGradientRelease(gradient);
31 CGColorSpaceRelease(colorSpace);
37 return CGRectMake(rect.origin.x + 0.5, rect.origin.y + 0.5, rect.size.width - 1, rect.size.height - 1);
40 void draw1PxStroke(CGContextRef context, CGPoint startPoint, CGPoint endPoint, CGColorRef color)
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);
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];
59 CGRect topHalf = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height/2);
66 CGRect arcRect = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height - arcHeight, rect.size.width, arcHeight);
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);
71 CGFloat angle = acos(arcRect.size.width / (2*arcRadius));
72 CGFloat startAngle =
radians(180) + angle;
73 CGFloat endAngle =
radians(360) - angle;
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));
CGRect rectFor1PxStroke(CGRect rect)
void drawLinearGradient(CGContextRef context, CGRect rect, CGColorRef startColor, CGColorRef endColor)
void draw1PxStroke(CGContextRef context, CGPoint startPoint, CGPoint endPoint, CGColorRef color)
CGMutablePathRef createArcPathFromBottomOfRect(CGRect rect, CGFloat arcHeight)
static double radians(double degrees)
void drawGlossAndGradient(CGContextRef context, CGRect rect, CGColorRef startColor, CGColorRef endColor)