From 80791838d70e573ea3665aa930204d38a3039967 Mon Sep 17 00:00:00 2001 From: Ryan Olson Date: Wed, 25 Jul 2012 15:16:48 -0700 Subject: [PATCH 1/3] modified PrettyKit to play nice with ARC --- .../Cells/PrettyCustomViewTableViewCell.h | 2 +- .../Cells/PrettyCustomViewTableViewCell.m | 6 ----- PrettyKit/Cells/PrettyGridTableViewCell.h | 4 +-- PrettyKit/Cells/PrettyGridTableViewCell.m | 25 ++----------------- .../PrettySegmentedControlTableViewCell.h | 2 +- .../PrettySegmentedControlTableViewCell.m | 3 +-- PrettyKit/Cells/PrettyTableViewCell.h | 18 ++++++------- PrettyKit/Cells/PrettyTableViewCell.m | 23 +++-------------- PrettyKit/PrettyDrawing.m | 6 ++--- PrettyKit/PrettyNavigationBar.h | 10 ++++---- PrettyKit/PrettyNavigationBar.m | 9 ------- PrettyKit/PrettyShadowPlainTableview.m | 2 +- PrettyKit/PrettyTabBar.h | 6 ++--- PrettyKit/PrettyTabBar.m | 7 ------ PrettyKit/PrettyToolbar.h | 8 +++--- PrettyKit/PrettyToolbar.m | 8 ------ 16 files changed, 35 insertions(+), 104 deletions(-) diff --git a/PrettyKit/Cells/PrettyCustomViewTableViewCell.h b/PrettyKit/Cells/PrettyCustomViewTableViewCell.h index 26363e3..ed51808 100644 --- a/PrettyKit/Cells/PrettyCustomViewTableViewCell.h +++ b/PrettyKit/Cells/PrettyCustomViewTableViewCell.h @@ -41,6 +41,6 @@ @interface PrettyCustomViewTableViewCell : PrettyTableViewCell /** Holds a reference to the custom view. */ -@property (nonatomic, retain) UIView *customView; +@property (nonatomic) UIView *customView; @end diff --git a/PrettyKit/Cells/PrettyCustomViewTableViewCell.m b/PrettyKit/Cells/PrettyCustomViewTableViewCell.m index 46a6d47..53b150a 100644 --- a/PrettyKit/Cells/PrettyCustomViewTableViewCell.m +++ b/PrettyKit/Cells/PrettyCustomViewTableViewCell.m @@ -35,12 +35,6 @@ @implementation PrettyCustomViewTableViewCell #define shadow_margin 4 -- (void) dealloc -{ - self.customView = nil; - - [super dealloc]; -} - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { diff --git a/PrettyKit/Cells/PrettyGridTableViewCell.h b/PrettyKit/Cells/PrettyGridTableViewCell.h index 9cf753d..3fa73b7 100644 --- a/PrettyKit/Cells/PrettyGridTableViewCell.h +++ b/PrettyKit/Cells/PrettyGridTableViewCell.h @@ -119,10 +119,10 @@ @property (nonatomic, assign) UITextAlignment textAlignment; /** Returns an array with all the texts in the grid. */ -@property (nonatomic, readonly) NSArray *texts; +@property (weak, nonatomic, readonly) NSArray *texts; /** Returns an array with all the detail texts in the grid. */ -@property (nonatomic, readonly) NSArray *detailTexts; +@property (weak, nonatomic, readonly) NSArray *detailTexts; /** Specifies if the shadow should be shown only on the selected element. diff --git a/PrettyKit/Cells/PrettyGridTableViewCell.m b/PrettyKit/Cells/PrettyGridTableViewCell.m index babf4cf..e3da5e8 100644 --- a/PrettyKit/Cells/PrettyGridTableViewCell.m +++ b/PrettyKit/Cells/PrettyGridTableViewCell.m @@ -36,7 +36,7 @@ @interface PrettyGridSubview : UIButton { BOOL _gradientVisible; } -@property (nonatomic, retain) PrettyGridTableViewCell *cell; +@property (nonatomic) PrettyGridTableViewCell *cell; @property (nonatomic, assign) int selectedSegment; @property (nonatomic, readonly) CGFloat segmentWidth; @@ -49,12 +49,6 @@ - (void) deselectAnimated:(BOOL)animated completion:(void (^)(void))block; @implementation PrettyGridSubview @synthesize cell, selectedSegment; -- (void) dealloc -{ - self.cell = nil; - - [super dealloc]; -} - (CGFloat) segmentWidth { @@ -313,7 +307,6 @@ - (void) deselectAnimated:(BOOL)animated completion:(void (^)(void))block } completion:^(BOOL finished) { [imageView removeFromSuperview]; - [imageView release]; if (block) { block(); } @@ -389,30 +382,20 @@ @implementation PrettyGridTableViewCell - (void) dealloc { if (_texts != nil) { - [_texts release]; _texts = nil; } if (_detailTexts != nil) { - [_detailTexts release]; _detailTexts = nil; } if (_currentIndexPath != nil) { - [_currentIndexPath release]; _currentIndexPath = nil; } - [super dealloc]; } - (void) initVars { - if (_texts != nil) { - [_texts release]; - } - if (_detailTexts != nil) { - [_detailTexts release]; - } _texts = [[NSMutableDictionary alloc] init]; _detailTexts = [[NSMutableDictionary alloc] init]; @@ -443,7 +426,6 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus PrettyGridSubview *subview = [[PrettyGridSubview alloc] init]; subview.cell = self; self.customView = subview; - [subview release]; self.elementSelectionStyle = UITableViewCellSelectionStyleBlue; self.textAlignment = UITextAlignmentCenter; @@ -520,10 +502,7 @@ - (void) prepareForTableView:(UITableView *)tableView indexPath:(NSIndexPath *)i { [super prepareForTableView:tableView indexPath:indexPath]; - if (_currentIndexPath != nil) { - [_currentIndexPath release]; - } - _currentIndexPath = [indexPath retain]; + _currentIndexPath = indexPath; } - (void) selectIndex:(int)index diff --git a/PrettyKit/Cells/PrettySegmentedControlTableViewCell.h b/PrettyKit/Cells/PrettySegmentedControlTableViewCell.h index ba187e4..026a72c 100644 --- a/PrettyKit/Cells/PrettySegmentedControlTableViewCell.h +++ b/PrettyKit/Cells/PrettySegmentedControlTableViewCell.h @@ -57,7 +57,7 @@ @interface PrettySegmentedControlTableViewCell : PrettyGridTableViewCell -@property (nonatomic, retain) NSArray *titles; +@property (nonatomic) NSArray *titles; @property (nonatomic, assign) NSInteger selectedIndex; @end diff --git a/PrettyKit/Cells/PrettySegmentedControlTableViewCell.m b/PrettyKit/Cells/PrettySegmentedControlTableViewCell.m index 75cc819..6b1d4d2 100644 --- a/PrettyKit/Cells/PrettySegmentedControlTableViewCell.m +++ b/PrettyKit/Cells/PrettySegmentedControlTableViewCell.m @@ -51,10 +51,9 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus // Initialization code selectedIndex = -1; - UIColor *tmp = [self.selectionGradientStartColor retain]; + UIColor *tmp = self.selectionGradientStartColor; self.selectionGradientStartColor = self.selectionGradientEndColor; self.selectionGradientEndColor = tmp; - [tmp release]; self.textLabel.shadowColor = [UIColor blackColor]; self.textLabel.shadowOffset = CGSizeMake(0, 1); diff --git a/PrettyKit/Cells/PrettyTableViewCell.h b/PrettyKit/Cells/PrettyTableViewCell.h index 1b8a295..217046b 100644 --- a/PrettyKit/Cells/PrettyTableViewCell.h +++ b/PrettyKit/Cells/PrettyTableViewCell.h @@ -129,19 +129,19 @@ typedef enum { `backgroundColor` property. Change this property to override the background color in plain table views. */ -@property (nonatomic, retain) UIColor *customBackgroundColor; +@property (nonatomic) UIColor *customBackgroundColor; /** Specifies the background gradient start color to use. */ -@property (nonatomic, retain) UIColor *gradientStartColor; +@property (nonatomic) UIColor *gradientStartColor; /** Specifies the background gradient end color to use. */ -@property (nonatomic, retain) UIColor *gradientEndColor; +@property (nonatomic) UIColor *gradientEndColor; /** Specifies the color used for the cell's border. If dropsShadow is set to `YES`, borderColor will be ignored. This property has a gray color by default. */ -@property (nonatomic, retain) UIColor *borderColor; +@property (nonatomic) UIColor *borderColor; /** Specifies the radio used for the cell's corners. @@ -151,7 +151,7 @@ typedef enum { /** Specifies the color used for the tableView's background. This property has a clearColor by default. */ -@property (nonatomic, retain) UIColor *tableViewBackgroundColor; +@property (nonatomic) UIColor *tableViewBackgroundColor; /** Specifies if a custom separator should be drawn. @@ -162,7 +162,7 @@ typedef enum { /** Specifies the color used for the cell's separator line. This property has a light gray color by default. */ -@property (nonatomic, retain) UIColor *customSeparatorColor; +@property (nonatomic) UIColor *customSeparatorColor; /** Specifies the start color for the selection gradient. @@ -171,7 +171,7 @@ typedef enum { If UITableViewCell's `selectionStyle` property is set to `UITableViewCellSelectionStyleNone`, no gradient will be shown. */ -@property (nonatomic, retain) UIColor *selectionGradientStartColor; +@property (nonatomic) UIColor *selectionGradientStartColor; /** Specifies the end color for the selection gradient. @@ -179,7 +179,7 @@ typedef enum { If UITableViewCell's `selectionStyle` property is set to `UITableViewCellSelectionStyleNone`, no gradient will be shown. */ -@property (nonatomic, retain) UIColor *selectionGradientEndColor; +@property (nonatomic) UIColor *selectionGradientEndColor; /** @name Cell configuration */ @@ -225,7 +225,7 @@ typedef enum { @property (nonatomic, readonly) CGRect innerFrame; /** Returns a mask with the rounded corners. */ -@property (nonatomic, readonly) CAShapeLayer *mask; +@property (weak, nonatomic, readonly) CAShapeLayer *mask; /** Returns a new gradient with the configured selection gradient colors. */ - (CGGradientRef) newSelectionGradient; diff --git a/PrettyKit/Cells/PrettyTableViewCell.m b/PrettyKit/Cells/PrettyTableViewCell.m index 003f607..07d8bad 100644 --- a/PrettyKit/Cells/PrettyTableViewCell.m +++ b/PrettyKit/Cells/PrettyTableViewCell.m @@ -82,7 +82,7 @@ - (float) shadowMargin { @interface PrettyTableViewCellBackground : UIView -@property (nonatomic, assign) PrettyTableViewCell *cell; +@property (nonatomic, weak) PrettyTableViewCell *cell; @property (nonatomic, assign) CellBackgroundBehavior behavior; - (id) initWithFrame:(CGRect)frame behavior:(CellBackgroundBehavior)behavior; @@ -315,7 +315,6 @@ - (void) dealloc { self.cell = nil; - [super dealloc]; } - (id) initWithFrame:(CGRect)frame behavior:(CellBackgroundBehavior)bbehavior @@ -349,16 +348,8 @@ @implementation PrettyTableViewCell - (void) dealloc { [self.contentView removeObserver:self forKeyPath:@"frame"]; - self.borderColor = nil; self.tableViewBackgroundColor = nil; - self.customSeparatorColor = nil; - self.selectionGradientStartColor = nil; - self.selectionGradientEndColor = nil; - self.customBackgroundColor = nil; - self.gradientStartColor = nil; - self.gradientEndColor = nil; - [super dealloc]; } - (void)initializeVars @@ -388,13 +379,11 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus behavior:CellBackgroundBehaviorNormal]; bg.cell = self; self.backgroundView = bg; - [bg release]; bg = [[PrettyTableViewCellBackground alloc] initWithFrame:self.frame behavior:CellBackgroundBehaviorSelected]; bg.cell = self; self.selectedBackgroundView = bg; - [bg release]; [self initializeVars]; } @@ -492,10 +481,6 @@ - (void) prepareForReuse - (void) setTableViewBackgroundColor:(UIColor *)aBackgroundColor { - [aBackgroundColor retain]; - if (tableViewBackgroundColor != nil) { - [tableViewBackgroundColor release]; - } tableViewBackgroundColor = aBackgroundColor; self.backgroundView.backgroundColor = aBackgroundColor; @@ -569,7 +554,7 @@ - (CAShapeLayer *) mask maskLayer.frame = maskRect; maskLayer.path = maskPath.CGPath; - return [maskLayer autorelease]; + return maskLayer; } - (BOOL) dropsShadow @@ -599,7 +584,7 @@ - (CGGradientRef) newSelectionGradient NSArray *colors = [NSArray arrayWithObjects:(id)self.selectionGradientStartColor.CGColor, (id)self.selectionGradientEndColor.CGColor, nil]; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, - (CFArrayRef) colors, locations); + (__bridge CFArrayRef) colors, locations); CGColorSpaceRelease(colorSpace); return gradient; @@ -617,7 +602,7 @@ - (CGGradientRef) newNormalGradient NSArray *colors = [NSArray arrayWithObjects:(id)self.gradientStartColor.CGColor, (id)self.gradientEndColor.CGColor, nil]; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, - (CFArrayRef) colors, locations); + (__bridge CFArrayRef) colors, locations); CGColorSpaceRelease(colorSpace); return gradient; diff --git a/PrettyKit/PrettyDrawing.m b/PrettyKit/PrettyDrawing.m index 0841c88..58648fb 100644 --- a/PrettyKit/PrettyDrawing.m +++ b/PrettyKit/PrettyDrawing.m @@ -42,12 +42,10 @@ + (void) drawGradient:(CGRect)rect fromColor:(UIColor *)from toColor:(UIColor *) CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[] = { 0.0, 1.0 }; - CGColorRef startColor = from.CGColor; - CGColorRef endColor = to.CGColor; - NSArray *colors = [NSArray arrayWithObjects:(id)startColor, (id)endColor, nil]; + NSArray *colors = [NSArray arrayWithObjects:(__bridge id)[from CGColor], (__bridge id)[to CGColor], nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, - (CFArrayRef) colors, locations); + (__bridge CFArrayRef) colors, locations); CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)); diff --git a/PrettyKit/PrettyNavigationBar.h b/PrettyKit/PrettyNavigationBar.h index f008dea..fde80a0 100644 --- a/PrettyKit/PrettyNavigationBar.h +++ b/PrettyKit/PrettyNavigationBar.h @@ -56,27 +56,27 @@ /** Specifies the gradient's start color. By default is a blue tone. */ -@property (nonatomic, retain) UIColor *gradientStartColor; +@property (nonatomic) UIColor *gradientStartColor; /** Specifies the gradient's end color. By default is a blue tone. */ -@property (nonatomic, retain) UIColor *gradientEndColor; +@property (nonatomic) UIColor *gradientEndColor; /** Specifies the gradient's top line color. By default is a blue tone. */ -@property (nonatomic, retain) UIColor *topLineColor; +@property (nonatomic) UIColor *topLineColor; /** Specifies the gradient's bottom line color. By default is a blue tone. */ -@property (nonatomic, retain) UIColor *bottomLineColor; +@property (nonatomic) UIColor *bottomLineColor; /** Specifies the background color for the rounded corners. By default is a black tone. */ -@property (nonatomic, retain) UIColor *roundedCornerColor; +@property (nonatomic) UIColor *roundedCornerColor; /** Specifies the radius for the rounded corners. diff --git a/PrettyKit/PrettyNavigationBar.m b/PrettyKit/PrettyNavigationBar.m index b53d2a1..41c387a 100644 --- a/PrettyKit/PrettyNavigationBar.m +++ b/PrettyKit/PrettyNavigationBar.m @@ -44,15 +44,6 @@ @implementation PrettyNavigationBar #define default_tint_color [UIColor colorWithHex:0x3D89BF] #define default_roundedcorner_color [UIColor blackColor] -- (void)dealloc { - self.gradientStartColor = nil; - self.gradientEndColor = nil; - self.topLineColor = nil; - self.bottomLineColor = nil; - self.roundedCornerColor = nil; - - [super dealloc]; -} - (void) initializeVars { diff --git a/PrettyKit/PrettyShadowPlainTableview.m b/PrettyKit/PrettyShadowPlainTableview.m index 94bc092..384e881 100644 --- a/PrettyKit/PrettyShadowPlainTableview.m +++ b/PrettyKit/PrettyShadowPlainTableview.m @@ -49,7 +49,7 @@ + (id) shadowForPosition:(PrettyShadowPlainTableviewPosition)position PrettyShadowPlainTableview *view = [[PrettyShadowPlainTableview alloc] initWithFrame:CGRectMake(0, 0, 0, view_height)]; view->_position = position; - return [view autorelease]; + return view; } diff --git a/PrettyKit/PrettyTabBar.h b/PrettyKit/PrettyTabBar.h index e20260f..e1d8d9d 100644 --- a/PrettyKit/PrettyTabBar.h +++ b/PrettyKit/PrettyTabBar.h @@ -46,16 +46,16 @@ /** Specifies the gradient's start color. By default is a black tone. */ -@property (nonatomic, retain) UIColor *gradientStartColor; +@property (nonatomic) UIColor *gradientStartColor; /** Specifies the gradient's end color. By default is a black tone. */ -@property (nonatomic, retain) UIColor *gradientEndColor; +@property (nonatomic) UIColor *gradientEndColor; /** Specifies the top separator's color. By default is a black tone. */ -@property (nonatomic, retain) UIColor *separatorLineColor; +@property (nonatomic) UIColor *separatorLineColor; @end diff --git a/PrettyKit/PrettyTabBar.m b/PrettyKit/PrettyTabBar.m index 3bf8514..9a4687b 100644 --- a/PrettyKit/PrettyTabBar.m +++ b/PrettyKit/PrettyTabBar.m @@ -37,13 +37,6 @@ @implementation PrettyTabBar @synthesize gradientStartColor, gradientEndColor, separatorLineColor; -- (void) dealloc { - self.gradientStartColor = nil; - self.gradientEndColor = nil; - self.separatorLineColor = nil; - - [super dealloc]; -} - (void) initializeVars { diff --git a/PrettyKit/PrettyToolbar.h b/PrettyKit/PrettyToolbar.h index 25b79ae..82e67d7 100644 --- a/PrettyKit/PrettyToolbar.h +++ b/PrettyKit/PrettyToolbar.h @@ -46,21 +46,21 @@ /** Specifies the gradient's start color. By default is a blue tone. */ -@property (nonatomic, retain) UIColor *gradientStartColor; +@property (nonatomic) UIColor *gradientStartColor; /** Specifies the gradient's end color. By default is a blue tone. */ -@property (nonatomic, retain) UIColor *gradientEndColor; +@property (nonatomic) UIColor *gradientEndColor; /** Specifies the gradient's top line color. By default is a blue tone. */ -@property (nonatomic, retain) UIColor *topLineColor; +@property (nonatomic) UIColor *topLineColor; /** Specifies the gradient's bottom line color. By default is a blue tone. */ -@property (nonatomic, retain) UIColor *bottomLineColor; +@property (nonatomic) UIColor *bottomLineColor; @end diff --git a/PrettyKit/PrettyToolbar.m b/PrettyKit/PrettyToolbar.m index a8a8bec..e97cb9a 100644 --- a/PrettyKit/PrettyToolbar.m +++ b/PrettyKit/PrettyToolbar.m @@ -36,14 +36,6 @@ @implementation PrettyToolbar #define default_bottom_line_color [UIColor colorWithHex:0x186399] #define default_tint_color [UIColor colorWithHex:0x3D89BF] -- (void)dealloc { - self.gradientStartColor = nil; - self.gradientEndColor = nil; - self.topLineColor = nil; - self.bottomLineColor = nil; - - [super dealloc]; -} - (void) initializeVars { From 02fe0f1375480ac94e1973f9925d81794bf61aa8 Mon Sep 17 00:00:00 2001 From: Silas Knobel Date: Sun, 6 Jan 2013 15:20:19 -0200 Subject: [PATCH 2/3] Added possibility to add a gradient with multiple colors --- PrettyKit/PrettyDrawing.h | 9 +++++++++ PrettyKit/PrettyDrawing.m | 34 +++++++++++++++++++++++++++++++++ PrettyKit/PrettyNavigationBar.h | 28 ++++++++++++++++++--------- PrettyKit/PrettyNavigationBar.m | 16 ++++++++++------ 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/PrettyKit/PrettyDrawing.h b/PrettyKit/PrettyDrawing.h index bff338e..d48e1ee 100644 --- a/PrettyKit/PrettyDrawing.h +++ b/PrettyKit/PrettyDrawing.h @@ -40,6 +40,15 @@ typedef enum { @interface PrettyDrawing : NSObject +/** + Draws a gradient with the given colors into the given rect. + + @param rect - CGRect where to draw the gradient + @param colors - An Array with UIColors + @param positions - An Array containing NSNumber's + */ ++ (void) drawGradient:(CGRect)rect withColors:(NSArray *)colors atPositions:(NSArray *)positions; + /** Draws a gradient with the given colors into the given rect. */ diff --git a/PrettyKit/PrettyDrawing.m b/PrettyKit/PrettyDrawing.m index 58648fb..30b03a6 100644 --- a/PrettyKit/PrettyDrawing.m +++ b/PrettyKit/PrettyDrawing.m @@ -32,6 +32,40 @@ @implementation PrettyDrawing ++ (void)drawGradient:(CGRect)rect withColors:(NSArray *)colors atPositions:(NSArray *)positions { + CGContextRef ctx = UIGraphicsGetCurrentContext(); + CGContextSaveGState(ctx); + + CGContextAddRect(ctx, rect); + CGContextClip(ctx); + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + CGFloat locations[positions.count]; + for (NSInteger i = 0; i < positions.count; i++) { + NSNumber *position = positions[i]; + locations[i] = [position floatValue]; + } + + + NSMutableArray *colorsCGRef = [NSMutableArray array]; + [colors enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [colorsCGRef addObject:(__bridge id)[(UIColor *)obj CGColor]]; + }]; + + CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, + (__bridge CFArrayRef) colorsCGRef, locations); + + CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); + CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)); + + CGContextDrawLinearGradient(ctx, gradient, startPoint, endPoint, 0); + CGGradientRelease(gradient); + CGColorSpaceRelease(colorSpace); + + CGContextRestoreGState(ctx); +} + + (void) drawGradient:(CGRect)rect fromColor:(UIColor *)from toColor:(UIColor *)to { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSaveGState(ctx); diff --git a/PrettyKit/PrettyNavigationBar.h b/PrettyKit/PrettyNavigationBar.h index fde80a0..9e20209 100644 --- a/PrettyKit/PrettyNavigationBar.h +++ b/PrettyKit/PrettyNavigationBar.h @@ -47,21 +47,31 @@ */ @interface PrettyNavigationBar : UINavigationBar +/** Specifies the gradient's colors + + By default it's a blue tone. */ +@property (nonatomic) NSArray *gradientColors; + +/** Specifies the gradient's color locations + + By default it's 0 and 1 */ +@property (nonatomic) NSArray *gradientLocations; + /** Specifies the navigation bar shadow's opacity. By default is `0.5`. */ @property (nonatomic, assign) float shadowOpacity; -/** Specifies the gradient's start color. - - By default is a blue tone. */ -@property (nonatomic) UIColor *gradientStartColor; - -/** Specifies the gradient's end color. - - By default is a blue tone. */ -@property (nonatomic) UIColor *gradientEndColor; +///** Specifies the gradient's start color. +// +// By default is a blue tone. */ +//@property (nonatomic) UIColor *gradientStartColor; +// +///** Specifies the gradient's end color. +// +// By default is a blue tone. */ +//@property (nonatomic) UIColor *gradientEndColor; /** Specifies the gradient's top line color. diff --git a/PrettyKit/PrettyNavigationBar.m b/PrettyKit/PrettyNavigationBar.m index 41c387a..0de3068 100644 --- a/PrettyKit/PrettyNavigationBar.m +++ b/PrettyKit/PrettyNavigationBar.m @@ -33,7 +33,7 @@ #import @implementation PrettyNavigationBar -@synthesize shadowOpacity, gradientEndColor, gradientStartColor, topLineColor, bottomLineColor, roundedCornerRadius, roundedCornerColor; +@synthesize shadowOpacity, topLineColor, bottomLineColor, roundedCornerRadius, roundedCornerColor, gradientColors, gradientLocations; #define default_shadow_opacity 0.5 @@ -43,19 +43,23 @@ @implementation PrettyNavigationBar #define default_bottom_line_color [UIColor colorWithHex:0x186399] #define default_tint_color [UIColor colorWithHex:0x3D89BF] #define default_roundedcorner_color [UIColor blackColor] - +#define default_gradient_start_location [NSNumber numberWithFloat:0.0] +#define default_gradient_end_location [NSNumber numberWithFloat:1.0] - (void) initializeVars { self.contentMode = UIViewContentModeRedraw; self.shadowOpacity = default_shadow_opacity; - self.gradientStartColor = default_gradient_start_color; - self.gradientEndColor = default_gradient_end_color; +// self.gradientStartColor = default_gradient_start_color; +// self.gradientEndColor = default_gradient_end_color; self.topLineColor = default_top_line_color; self.bottomLineColor = default_bottom_line_color; self.tintColor = default_tint_color; self.roundedCornerColor = default_roundedcorner_color; self.roundedCornerRadius = 0.0; + self.gradientColors = @[default_gradient_start_color,default_gradient_end_color]; + self.gradientLocations = @[default_gradient_start_location,default_gradient_end_location]; + } - (id)initWithCoder:(NSCoder *)coder { @@ -116,8 +120,8 @@ - (void) drawRect:(CGRect)rect { [super drawRect:rect]; [self dropShadowWithOpacity:self.shadowOpacity]; - [PrettyDrawing drawGradient:rect fromColor:self.gradientStartColor toColor:self.gradientEndColor]; - [self drawTopLine:rect]; + [PrettyDrawing drawGradient:rect withColors:self.gradientColors atPositions:self.gradientLocations]; + [self drawTopLine:rect]; [self drawBottomLine:rect]; if (self.roundedCornerRadius > 0) { From fab73d48f852d924f7ea71455eb7186b15648330 Mon Sep 17 00:00:00 2001 From: codyhazelwood Date: Thu, 9 May 2013 23:08:56 -0500 Subject: [PATCH 3/3] Fixed observation data leak with PrettyTableViewCell --- PrettyKit/Cells/PrettyTableViewCell.m | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/PrettyKit/Cells/PrettyTableViewCell.m b/PrettyKit/Cells/PrettyTableViewCell.m index 07d8bad..ae224d8 100644 --- a/PrettyKit/Cells/PrettyTableViewCell.m +++ b/PrettyKit/Cells/PrettyTableViewCell.m @@ -390,6 +390,28 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus return self; } +- (id)initWithCoder:(NSCoder *)aDecoder +{ + self = [super initWithCoder:aDecoder]; + if (self) { + + [self.contentView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionOld context:nil]; + + + PrettyTableViewCellBackground *bg = [[PrettyTableViewCellBackground alloc] initWithFrame:self.frame + behavior:CellBackgroundBehaviorNormal]; + bg.cell = self; + self.backgroundView = bg; + + bg = [[PrettyTableViewCellBackground alloc] initWithFrame:self.frame + behavior:CellBackgroundBehaviorSelected]; + bg.cell = self; + self.selectedBackgroundView = bg; + + [self initializeVars]; + } + return self; +} + (PrettyTableViewCellPosition) positionForTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath { @@ -608,6 +630,9 @@ - (CGGradientRef) newNormalGradient return gradient; } - +- (void) dealloc +{ + [self.contentView removeObserver:self forKeyPath:@"frame" context:nil]; +} @end