Created
August 7, 2013 14:49
-
-
Save Shosta/6174717 to your computer and use it in GitHub Desktop.
Allow the developer to set a custom color or gradient to a GRoupedTableViewCell by using the [UISelectedTableViewCell configureSelectedBackgroundForCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath forRowCount:(int)rowCount]; It is useful prior to iOS7 as there is no more GroupedTableViewCell on iOS7. Moreover the developer can s…
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
// | |
// OLGradientView.h | |
// | |
// | |
// Created by Rémi LAVEDRINE on 5/6/09. | |
// Copyright Rémi LAVEDRINE 2009. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface OLGradientView : UIView { | |
CGFloat _colorComponents[8]; | |
} | |
- (id)initWithColor: (UIColor *)bColor andDestinationColor: (UIColor *)dColor; | |
- (void)setBaseColor: (UIColor *)bColor andDestinationColor: (UIColor *)dColor; | |
@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
// | |
// OLGradientView.m | |
// | |
// | |
// Created by Rémi LAVEDRINE on 5/6/09. | |
// Copyright Rémi LAVEDRINE 2009. All rights reserved. | |
// | |
#import "OLGradientView.h" | |
#import "OLFunctions.h" | |
@implementation OLGradientView | |
- (id)initWithFrame:(CGRect)frame { | |
if ((self = [super initWithFrame:frame])) { | |
[self setBaseColor: [UIColor redColor] andDestinationColor: [UIColor greenColor]]; | |
} | |
return self; | |
} | |
- (id)initWithColor: (UIColor *)bColor andDestinationColor: (UIColor *)dColor { | |
if ((self=[super init])) | |
{ | |
[self setBaseColor:bColor andDestinationColor:dColor]; | |
} | |
return self; | |
} | |
- (void)drawRect:(CGRect)rect { | |
[super drawRect: rect]; | |
// if the 2 colors of the gradient are the same, there is no gradient | |
if (colorComponentsContainsDifferentColors(_colorComponents)){ | |
CGContextRef ctxt = UIGraphicsGetCurrentContext(); | |
float totalHeight = CGRectGetHeight(self.frame); | |
CGColorSpaceRef cellColorspace = CGColorSpaceCreateDeviceRGB(); | |
if (cellColorspace){ | |
CGGradientRef gradient; | |
size_t num_locations = 2; | |
CGFloat locations[2] = { 0.0, 1.0 }; | |
gradient = CGGradientCreateWithColorComponents (cellColorspace, _colorComponents, locations, num_locations); | |
CGPoint startPoint, endPoint; | |
startPoint.x = 0.0; | |
startPoint.y = totalHeight; | |
endPoint.x = 0; | |
endPoint.y = 0; | |
CGContextDrawLinearGradient (ctxt, gradient, startPoint, endPoint, 0); | |
CGColorSpaceRelease(cellColorspace); | |
CFRelease(gradient); | |
} | |
} | |
} | |
- (void)dealloc { | |
[super dealloc]; | |
} | |
- (void)setBaseColor: (UIColor *)bColor andDestinationColor: (UIColor *)dColor{ | |
setColorComponentsFromColors(_colorComponents, bColor, dColor); | |
} | |
@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
// | |
// OLGroupedTableViewCellSelectedBackground.h | |
// | |
// | |
// Created by Rémi LAVEDRINE on 09/11/12. | |
// Copyright (c) 2012 Rémi LAVEDRINE. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
typedef enum | |
{ | |
CustomCellBackgroundViewPositionTop, | |
CustomCellBackgroundViewPositionMiddle, | |
CustomCellBackgroundViewPositionBottom, | |
CustomCellBackgroundViewPositionSingle | |
} CustomCellBackgroundViewPosition; | |
@interface OLGroupedTableViewCellSelectedBackground : UIView{ | |
CustomCellBackgroundViewPosition position; | |
} | |
@property(nonatomic) CustomCellBackgroundViewPosition position; | |
- (CGGradientRef)newGradient:(UIColor *)baseColor andDestinationColor:(UIColor *)destinationColor; | |
- (void)setGradient:(UIColor *)baseColor andDestinationColor:(UIColor *)destinationColor; | |
@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
// | |
// OLGroupedTableViewCellSelectedBackground.m | |
// | |
// | |
// Created by Rémi LAVEDRINE on 09/11/12. | |
// Copyright (c) 2012 Rémi LAVEDRINE. All rights reserved. | |
// | |
#import "OLGroupedTableViewCellSelectedBackground.h" | |
#import "OLFunctions.h" | |
#define ROUND_SIZE 10 | |
@interface OLGroupedTableViewCellSelectedBackground () | |
@property(nonatomic, assign) CGGradientRef CGGradient; | |
@end | |
@implementation OLGroupedTableViewCellSelectedBackground | |
@synthesize position; | |
@synthesize CGGradient = _CGGradient; | |
#pragma mark - Object | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
// Initialization code | |
CGGradientRef gradientRef = [self newGradient:[UIColor blackColor] andDestinationColor:[UIColor whiteColor]]; | |
self.CGGradient = gradientRef; | |
CGGradientRelease(gradientRef); | |
} | |
return self; | |
} | |
#pragma mark - Drawing | |
- (void)drawRect:(CGRect)rect{ | |
// Drawing code | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
UIBezierPath* roundedRectanglePath; | |
if(position == CustomCellBackgroundViewPositionTop) | |
{ | |
roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: CGSizeMake(10, 10)]; | |
} | |
else if (position == CustomCellBackgroundViewPositionBottom) | |
{ | |
roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: CGSizeMake(10, 10)]; | |
} | |
else if (position == CustomCellBackgroundViewPositionMiddle) | |
{ | |
roundedRectanglePath = [UIBezierPath bezierPathWithRect:rect]; | |
} | |
else | |
{ | |
roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:10]; | |
} | |
CGContextSaveGState(context); | |
[roundedRectanglePath addClip]; | |
CGContextDrawLinearGradient(context, self.CGGradient, | |
CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)), | |
CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)), | |
0); | |
CGContextRestoreGState(context); | |
[[UIColor lightGrayColor] setStroke]; | |
roundedRectanglePath.lineWidth = 1; | |
[roundedRectanglePath stroke]; | |
//// Cleanup | |
CGColorSpaceRelease(colorSpace); | |
} | |
- (CGGradientRef)newGradient:(UIColor *)baseColor andDestinationColor:(UIColor *)destinationColor{ | |
CGFloat _colorComponents[8]; | |
setColorComponentsFromColors(_colorComponents, baseColor, destinationColor); | |
CGColorSpaceRef cellColorspace = CGColorSpaceCreateDeviceRGB(); | |
size_t num_locations = 2; | |
CGFloat locations[2] = { 0.0, 1.0 }; | |
CGGradientRef lGradient = CGGradientCreateWithColorComponents(cellColorspace, _colorComponents, locations, num_locations); | |
CGColorSpaceRelease(cellColorspace); | |
return lGradient; | |
} | |
- (void)setGradient:(UIColor *)baseColor andDestinationColor:(UIColor *)destinationColor{ | |
CGGradientRef gradientRef = [self newGradient:baseColor andDestinationColor:destinationColor]; | |
self.CGGradient = gradientRef; | |
CGGradientRelease(gradientRef); | |
} | |
#pragma mark - Custom Setters | |
- (void)setCGGradient:(CGGradientRef)g { | |
if (g != self.CGGradient){ | |
if (self.CGGradient) | |
CGGradientRelease(_CGGradient); | |
_CGGradient = CGGradientRetain(g); | |
} | |
} | |
#pragma mark - Memory | |
- (void)dealloc{ | |
if (_CGGradient){ | |
CGGradientRelease(_CGGradient); | |
_CGGradient = NULL; | |
} | |
[super dealloc]; | |
} | |
@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
// | |
// OLFunctions.h | |
// | |
// | |
// Created by Rémi LAVEDRINE on 14/10/09. | |
// Copyright Rémi LAVEDRINE 2009. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
#define SUPPORTS_UNDOCUMENTED_API 0 | |
@interface UIColor (expanded) | |
- (CGColorSpaceModel) colorSpaceModel; | |
- (NSString *) colorSpaceString; | |
- (BOOL) canProvideRGBComponents; | |
- (NSArray *) arrayFromRGBAComponents; | |
- (CGFloat) red; | |
- (CGFloat) blue; | |
- (CGFloat) green; | |
- (CGFloat) alpha; | |
- (NSString *) stringFromColor; | |
- (NSString *) hexStringFromColor; | |
#if SUPPORTS_UNDOCUMENTED_API | |
// Optional Undocumented API calls | |
- (NSString *) fetchStyleString; | |
- (UIColor *) rgbColor; // Via Poltras | |
#endif | |
+ (UIColor *) colorWithString: (NSString *) stringToConvert; | |
+ (UIColor *) colorWithHexString: (NSString *) stringToConvert; | |
+ (UIColor *)orangeColorBranded; | |
+ (UIColor *)greigeColorBranded; | |
@property (nonatomic, readonly) CGFloat red; | |
@property (nonatomic, readonly) CGFloat green; | |
@property (nonatomic, readonly) CGFloat blue; | |
@property (nonatomic, readonly) CGFloat alpha; | |
@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
// | |
// OLFunctions.h | |
// | |
// | |
// Created by Rémi LAVEDRINE on 14/10/09. | |
// Copyright Rémi LAVEDRINE 2009. All rights reserved. | |
// | |
#import "UIColor-Expanded.h" | |
// Undocumented UIColor calls | |
@interface UIColor (undocumented) | |
- (NSString *)styleString; | |
@end | |
// Color to return when constructor cannot create a proper color -- can be nil | |
#define DEFAULT_VOID_COLOR [UIColor clearColor] | |
@implementation UIColor (expanded) | |
// Return a UIColor's color space model | |
- (CGColorSpaceModel) colorSpaceModel | |
{ | |
return CGColorSpaceGetModel(CGColorGetColorSpace(self.CGColor)); | |
} | |
- (NSString *) colorSpaceString | |
{ | |
switch ([self colorSpaceModel]) | |
{ | |
case kCGColorSpaceModelUnknown: | |
return @"kCGColorSpaceModelUnknown"; | |
case kCGColorSpaceModelMonochrome: | |
return @"kCGColorSpaceModelMonochrome"; | |
case kCGColorSpaceModelRGB: | |
return @"kCGColorSpaceModelRGB"; | |
case kCGColorSpaceModelCMYK: | |
return @"kCGColorSpaceModelCMYK"; | |
case kCGColorSpaceModelLab: | |
return @"kCGColorSpaceModelLab"; | |
case kCGColorSpaceModelDeviceN: | |
return @"kCGColorSpaceModelDeviceN"; | |
case kCGColorSpaceModelIndexed: | |
return @"kCGColorSpaceModelIndexed"; | |
case kCGColorSpaceModelPattern: | |
return @"kCGColorSpaceModelPattern"; | |
default: | |
return @"Not a valid color space"; | |
} | |
} | |
- (BOOL) canProvideRGBComponents | |
{ | |
return (([self colorSpaceModel] == kCGColorSpaceModelRGB) || | |
([self colorSpaceModel] == kCGColorSpaceModelMonochrome)); | |
} | |
// Return a UIColor's components | |
- (NSArray *) arrayFromRGBAComponents | |
{ | |
const CGFloat *c = CGColorGetComponents(self.CGColor); | |
// RGB | |
if ([self colorSpaceModel] == kCGColorSpaceModelRGB) | |
return [NSArray arrayWithObjects: | |
[NSNumber numberWithFloat:c[0]], | |
[NSNumber numberWithFloat:c[1]], | |
[NSNumber numberWithFloat:c[2]], | |
[NSNumber numberWithFloat:c[3]], | |
nil]; | |
// Monochrome | |
if ([self colorSpaceModel] == kCGColorSpaceModelMonochrome) | |
return [NSArray arrayWithObjects: | |
[NSNumber numberWithFloat:c[0]], | |
[NSNumber numberWithFloat:c[0]], | |
[NSNumber numberWithFloat:c[0]], | |
[NSNumber numberWithFloat:c[1]], | |
nil]; | |
// No support at this time for other color spaces yet | |
return nil; | |
} | |
#if SUPPORTS_UNDOCUMENTED_API | |
// Return the undocumented style string | |
- (NSString *) fetchStyleString | |
{ | |
return [self styleString]; | |
} | |
// Convert a color into RGB Color space, courtesy of Poltras | |
// via http://ofcodeandmen.poltras.com/2009/01/22/convert-a-cgcolorref-to-another-cgcolorspaceref/ | |
// | |
- (UIColor *) rgbColor | |
{ | |
// Call to undocumented method "styleString". | |
NSString*style = [self styleString]; | |
// Remove the "rgb(" prefix and the ")" suffix. | |
style = [[style substringToIndex:style.length - 1] substringFromIndex:4]; | |
// Split the components. | |
NSArray* rgb = [style componentsSeparatedByString:@","]; | |
CGFloat red = [[rgb objectAtIndex:0] floatValue] / 255.0f; | |
CGFloat green = [[rgb objectAtIndex:1] floatValue] / 255.0f; | |
CGFloat blue = [[rgb objectAtIndex:2] floatValue] / 255.0f; | |
CGFloat alpha = CGColorGetAlpha(self.CGColor); | |
return [UIColor colorWithRed:red | |
green:green | |
blue:blue | |
alpha:alpha]; | |
} | |
#endif | |
- (CGFloat) red | |
{ | |
NSAssert (self.canProvideRGBComponents, @"Must be a RGB color to use -red, -green, -blue"); | |
const CGFloat *c = CGColorGetComponents(self.CGColor); | |
return c[0]; | |
} | |
- (CGFloat) green | |
{ | |
NSAssert (self.canProvideRGBComponents, @"Must be a RGB color to use -red, -green, -blue"); | |
const CGFloat *c = CGColorGetComponents(self.CGColor); | |
if ([self colorSpaceModel] == kCGColorSpaceModelMonochrome) return c[0]; | |
return c[1]; | |
} | |
- (CGFloat) blue | |
{ | |
NSAssert (self.canProvideRGBComponents, @"Must be a RGB color to use -red, -green, -blue"); | |
const CGFloat *c = CGColorGetComponents(self.CGColor); | |
if ([self colorSpaceModel] == kCGColorSpaceModelMonochrome) return c[0]; | |
return c[2]; | |
} | |
- (CGFloat) alpha | |
{ | |
const CGFloat *c = CGColorGetComponents(self.CGColor); | |
return c[CGColorGetNumberOfComponents(self.CGColor)-1]; | |
} | |
/* | |
* | |
* String Utilities | |
* | |
*/ | |
- (NSString *) stringFromColor | |
{ | |
NSAssert (self.canProvideRGBComponents, @"Must be a RGB color to use stringFromColor"); | |
return [NSString stringWithFormat:@"{%0.3f, %0.3f, %0.3f, %0.3f}", self.red, self.green, self.blue, self.alpha]; | |
} | |
- (NSString *) hexStringFromColor | |
{ | |
NSAssert (self.canProvideRGBComponents, @"Must be a RGB color to use hexStringFromColor"); | |
CGFloat r, g, b; | |
r = self.red; | |
g = self.green; | |
b = self.blue; | |
// Fix range if needed | |
if (r < 0.0f) r = 0.0f; | |
if (g < 0.0f) g = 0.0f; | |
if (b < 0.0f) b = 0.0f; | |
if (r > 1.0f) r = 1.0f; | |
if (g > 1.0f) g = 1.0f; | |
if (b > 1.0f) b = 1.0f; | |
// Convert to hex string between 0x00 and 0xFF | |
return [NSString stringWithFormat:@"%02X%02X%02X", | |
(int)(r * 255), (int)(g * 255), (int)(b * 255)]; | |
} | |
+ (UIColor *) colorWithString: (NSString *) stringToConvert | |
{ | |
NSString *cString = [stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
// Proper color strings are denoted with braces | |
if (![cString hasPrefix:@"{"]) return DEFAULT_VOID_COLOR; | |
if (![cString hasSuffix:@"}"]) return DEFAULT_VOID_COLOR; | |
// Remove braces | |
cString = [cString substringFromIndex:1]; | |
cString = [cString substringToIndex:([cString length] - 1)]; | |
CFShow(cString); | |
// Separate into components by removing commas and spaces | |
NSArray *components = [cString componentsSeparatedByString:@", "]; | |
if ([components count] != 4) return DEFAULT_VOID_COLOR; | |
// Create the color | |
return [UIColor colorWithRed:[[components objectAtIndex:0] floatValue] | |
green:[[components objectAtIndex:1] floatValue] | |
blue:[[components objectAtIndex:2] floatValue] | |
alpha:[[components objectAtIndex:3] floatValue]]; | |
} | |
+ (UIColor *) colorWithHexString: (NSString *) stringToConvert | |
{ | |
NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; | |
// String should be 6 or 8 characters | |
if ([cString length] < 6) return DEFAULT_VOID_COLOR; | |
// strip 0X if it appears | |
if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2]; | |
if ([cString length] != 6) return DEFAULT_VOID_COLOR; | |
// Separate into r, g, b substrings | |
NSRange range; | |
range.location = 0; | |
range.length = 2; | |
NSString *rString = [cString substringWithRange:range]; | |
range.location = 2; | |
NSString *gString = [cString substringWithRange:range]; | |
range.location = 4; | |
NSString *bString = [cString substringWithRange:range]; | |
// Scan values | |
unsigned int r, g, b; | |
[[NSScanner scannerWithString:rString] scanHexInt:&r]; | |
[[NSScanner scannerWithString:gString] scanHexInt:&g]; | |
[[NSScanner scannerWithString:bString] scanHexInt:&b]; | |
return [UIColor colorWithRed:((float) r / 255.0f) | |
green:((float) g / 255.0f) | |
blue:((float) b / 255.0f) | |
alpha:1.0f]; | |
} | |
+ (UIColor *)orangeColorBranded; | |
{ | |
UIColor *orangeColor = [UIColor colorWithRed: 1 green: 0.4 blue: 0 alpha: 1]; | |
return orangeColor; | |
} | |
+ (UIColor *)greigeColorBranded; | |
{ | |
//UIColor *greigeColor = [UIColor colorWithRed: 0.9 green: 0.9 blue: 0.9 alpha: 1]; | |
UIColor *greigeColor = [UIColor colorWithHexString:@"e2e1dd"]; | |
return greigeColor; | |
} | |
@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
//-------------------------------------------------------- | |
// | |
//-------------------------------------------------------- | |
// Project : | |
// File : UISelectedTableViewCell.h | |
// Created : $ 03/10/12 $ | |
// Maintainer : $ Rémi LAVEDRINE $ | |
// | |
// Copyright Rémi LAVEDRINE 2004-2012, All Rights Reserved | |
// | |
// This software is the confidential and proprietary | |
// information of Rémi LAVEDRINE. | |
// You shall not disclose such Confidential Information | |
// and shall use it only in accordance with the terms | |
// of the license agreement you entered into with | |
// Rémi LAVEDRINE. | |
//-------------------------------------------------------- | |
// | |
// @brief | |
// | |
#import <Foundation/Foundation.h> | |
//! @brief <#Class comments#> | |
//! @class UISelectedTableViewCell | |
//! @ingroup Utilities | |
//! @author Rémi Lavedrine | |
@interface UISelectedTableViewCell : NSObject | |
//! Configure the selected background for a cell according to its indexPath. | |
//! @param[in] cell : The cell we want to change the selectedBackgroundView to an orange one. | |
//! @param[in] indexPath : The cell's indexPath. | |
//! @param[in] rowCount : The row count for the section that contains the "cell"'s object. | |
+ (void)configureSelectedBackgroundForCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath forRowCount:(int)rowCount; | |
//! Set a custom accessoryView to the given cell. | |
//! @param[in] cell : The cell we want to change the selectedBackgroundView to an orange one. | |
+ (void)addCustomAccessoryViewOnCell:(UITableViewCell *)cell; | |
@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
// | |
// UISelectedTableViewCell.m | |
// | |
// | |
// Created by Rémi LAVEDRINE on 03/10/12. | |
// Copyright (c) 2012 Rémi LAVEDRINE. All rights reserved. | |
// | |
#import "UISelectedTableViewCell.h" | |
#import "UITableViewCell+Background.h" | |
@implementation UISelectedTableViewCell | |
/** | |
@brief Configure the selected background for a cell according to its indexPath. | |
@author : Rémi Lavedrine | |
@date : 03/10/2012 | |
@remarks : <#(optional)#> | |
*/ | |
+ (void)configureSelectedBackgroundForCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath forRowCount:(int)rowCount{ | |
UIView *v = [[UIView alloc] init]; | |
[v setBackgroundColor:SELECTED_CELL_BACKGROUND_COLOR]; | |
[cell setSelectedBackgroundView:v]; | |
[v release]; | |
/*if ( rowCount == 1 ) { | |
[cell setSelectedBackgroundView:[UITableViewCell roundCornerBackgroundViewAtPosition:CustomCellBackgroundViewPositionSingle]]; | |
return; | |
} | |
if ( indexPath.row == 0 ) | |
{ | |
[cell setSelectedBackgroundView:[UITableViewCell roundCornerBackgroundViewAtPosition:CustomCellBackgroundViewPositionTop]]; | |
return; | |
} | |
else if ( indexPath.row == rowCount - 1 ) | |
{ | |
[cell setSelectedBackgroundView:[UITableViewCell roundCornerBackgroundViewAtPosition:CustomCellBackgroundViewPositionBottom]]; | |
return; | |
} | |
else | |
{ | |
[cell setSelectedBackgroundView:[UITableViewCell roundCornerBackgroundViewAtPosition:CustomCellBackgroundViewPositionMiddle]]; | |
return; | |
}*/ | |
} | |
/** | |
@brief Set a custom accessoryView to the given cell. | |
@author : Rémi Lavedrine | |
@date : 29/11/2012 | |
@remarks : <#(optional)#> | |
*/ | |
+ (void)addCustomAccessoryViewOnCell:(UITableViewCell *)cell{ | |
UIImageView * accessoryImageView =[[ UIImageView alloc ] initWithImage:[UIImage imageNamed:@"chevron"]]; | |
[accessoryImageView setHighlightedImage:[UIImage imageNamed:@"chevron_on"]]; | |
[cell setAccessoryView:accessoryImageView]; | |
[accessoryImageView release]; | |
} | |
@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
// | |
// UITableViewCell+Background.m | |
// | |
// | |
// Created by Rémi LAVEDRINE on 07/02/11. | |
// Copyright 2011 Rémi LAVEDRINE. All rights reserved. | |
// | |
#import "UITableViewCell+Background.h" | |
@implementation UITableViewCell (UITableViewCell_Background) | |
+(UIView*)backgroundGradientView:(UIColor*)color alpha:(CGFloat)alpha { | |
OLGradientView *bgView = [[OLGradientView alloc] initWithFrame: CGRectZero]; | |
CGColorRef baseColorClearRef = CGColorCreateCopyWithAlpha(color.CGColor, alpha); | |
UIColor *baseColorClear = [UIColor colorWithCGColor:baseColorClearRef]; | |
CGColorRelease(baseColorClearRef); | |
[bgView setBaseColor:color andDestinationColor:baseColorClear]; | |
[bgView setBackgroundColor: [UIColor clearColor]]; | |
return [bgView autorelease]; | |
} | |
+(UIView*)backgroundGradientView:(UIColor*)color { | |
return [UITableViewCell backgroundGradientView:color alpha:0.7]; | |
} | |
+ (UIView*)roundCornerBackgroundGradientViewWithColor:(UIColor*)color atPosition:(CustomCellBackgroundViewPosition)position { | |
OLGroupedTableViewCellSelectedBackground *selectedBackgroundView = [[OLGroupedTableViewCellSelectedBackground alloc] initWithFrame: CGRectZero]; | |
selectedBackgroundView.position = position; | |
UIColor *baseColor = color; | |
CGColorRef baseColorClearRef = CGColorCreateCopyWithAlpha(baseColor.CGColor, 0.7); | |
UIColor *baseColorClear = [UIColor colorWithCGColor:baseColorClearRef]; | |
CGColorRelease(baseColorClearRef); | |
[selectedBackgroundView setGradient:baseColor andDestinationColor:baseColorClear]; | |
[selectedBackgroundView setBackgroundColor: [UIColor clearColor]]; | |
return [selectedBackgroundView autorelease]; | |
} | |
+ (UIView*)roundCornerBackgroundViewWithColor:(UIColor*)color atPosition:(CustomCellBackgroundViewPosition)position { | |
OLGroupedTableViewCellSelectedBackground *selectedBackgroundView = [[OLGroupedTableViewCellSelectedBackground alloc] initWithFrame: CGRectZero]; | |
selectedBackgroundView.position = position; | |
UIColor *baseColor = color; | |
CGColorRef baseColorClearRef = CGColorCreateCopyWithAlpha(baseColor.CGColor, 1.0); | |
UIColor *baseColorClear = [UIColor colorWithCGColor:baseColorClearRef]; | |
CGColorRelease(baseColorClearRef); | |
[selectedBackgroundView setGradient:baseColor andDestinationColor:baseColorClear]; | |
[selectedBackgroundView setBackgroundColor:[UIColor clearColor]]; | |
return [selectedBackgroundView autorelease]; | |
} | |
+ (UIView*)backgroundGradientView { | |
return [UITableViewCell backgroundGradientView:SELECTED_CELL_BACKGROUND_COLOR]; | |
} | |
+ (UIView*)roundCornerBackgroundGradientView { | |
return [UITableViewCell roundCornerBackgroundGradientViewWithColor:SELECTED_CELL_BACKGROUND_COLOR | |
atPosition:CustomCellBackgroundViewPositionSingle]; | |
} | |
+ (UIView*)roundCornerBackgroundGradientViewAtPosition:(CustomCellBackgroundViewPosition)position { | |
return [UITableViewCell roundCornerBackgroundGradientViewWithColor:SELECTED_CELL_BACKGROUND_COLOR | |
atPosition:position]; | |
} | |
+ (UIView*)roundCornerBackgroundViewAtPosition:(CustomCellBackgroundViewPosition)position { | |
return [UITableViewCell roundCornerBackgroundViewWithColor:SELECTED_CELL_BACKGROUND_COLOR | |
atPosition:position]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment