-
-
Save Jeswang/3087525 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// UIView+CommonDrawing.h | |
// Contacts Plus | |
// | |
// Created by Tony Arnold on 4/08/10. | |
// Copyright 2010 The CocoaBots. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface UIView (CommonDrawing) | |
+(void)drawSelectionGradientWithBounds:(CGRect)bounds intoContext:(CGContextRef)context; | |
@end |
This file contains 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
// | |
// UIView+CommonDrawing.m | |
// Contacts Plus | |
// | |
// Created by Tony Arnold on 4/08/10. | |
// Copyright 2010 The CocoaBots. All rights reserved. | |
// | |
#import "UIView+CommonDrawing.h" | |
#import <QuartzCore/QuartzCore.h> | |
@implementation UIView (CommonDrawing) | |
+ (void)drawSelectionGradientWithBounds:(CGRect)gradientBounds intoContext:(CGContextRef)context { | |
if (CGRectEqualToRect(gradientBounds, CGRectZero) || (context == NULL)) { | |
return; | |
} | |
CGContextSaveGState(context); | |
// Draw a highlight | |
size_t num_locations = 2; | |
CGFloat locations[2] = { 0.0, 1.0 }; | |
CGFloat components[8] = { 0.021, 0.548, 0.962, 1.000, 0.008, 0.364, 0.900, 1.000 }; | |
CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB(); | |
CGGradientRef selectionGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations); | |
CGPoint startPoint = CGPointMake(CGRectGetMidX(gradientBounds), CGRectGetMinY(gradientBounds)); | |
CGPoint endPoint = CGPointMake(CGRectGetMidX(gradientBounds), CGRectGetMaxY(gradientBounds)); | |
CGContextDrawLinearGradient(context, selectionGradient, startPoint, endPoint, 0); | |
CGGradientRelease(selectionGradient); | |
CGColorSpaceRelease(rgbColorspace); | |
CGContextRestoreGState(context); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment