Skip to content

Instantly share code, notes, and snippets.

@Jeswang
Forked from tonyarnold/UIView+CommonDrawing.h
Created July 11, 2012 02:18
Show Gist options
  • Save Jeswang/3087525 to your computer and use it in GitHub Desktop.
Save Jeswang/3087525 to your computer and use it in GitHub Desktop.
//
// 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
//
// 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