Skip to content

Instantly share code, notes, and snippets.

@kmussel
Created July 3, 2012 13:53
Show Gist options
  • Save kmussel/3039819 to your computer and use it in GitHub Desktop.
Save kmussel/3039819 to your computer and use it in GitHub Desktop.
CGContextRef currentContext = UIGraphicsGetCurrentContext();
if(self.selected)
{
CGColorSpaceRef colorSpace =CGColorSpaceCreateDeviceRGB();
UIColor *startColor = [UIColor fromHexString:@"222222"];
CGFloat *startColorComponents =(CGFloat *)CGColorGetComponents([startColor CGColor]);
UIColor *endColor = [UIColor fromHexString:@"444444"];
CGFloat *endColorComponents =(CGFloat *)CGColorGetComponents([endColor CGColor]);
CGFloat colorComponents[8] = {
/* Four components of the start color (RGBA) */
startColorComponents[0],startColorComponents[1],startColorComponents[2],startColorComponents[3],
/* Four components of the end color (RGBA) */
endColorComponents[0],endColorComponents[1],endColorComponents[2],endColorComponents[3],};
CGFloat colorIndices[2] = {0.0f, 1.0f};
CGGradientRef gradient =CGGradientCreateWithColorComponents(colorSpace,(const CGFloat *)&colorComponents,(const CGFloat *)&colorIndices,2);
CGColorSpaceRelease(colorSpace);
CGPoint startPoint, endPoint;
CGFloat gradientWidth = 20.0;
CGFloat endwidth = (tanf(self.bounds.size.height/self.bounds.size.width))*gradientWidth;
CGFloat hoffset = sqrt((gradientWidth*gradientWidth)-(endwidth*endwidth));
CGFloat xoffset = 10;
startPoint = CGPointMake((self.bounds.size.width/2-endwidth)+xoffset, self.bounds.size.height/2-hoffset);
endPoint = CGPointMake((self.bounds.size.width/2+endwidth)+xoffset, self.bounds.size.height/2+hoffset);
CGContextDrawLinearGradient(currentContext,gradient,startPoint,endPoint,kCGGradientDrawsBeforeStartLocation |kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradient);
}
else
{
self.titleLabel.font = [UIFont fontWithName:@"Gotham-Medium" size:12];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment