Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PrettyKit/Cells/PrettyCustomViewTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
@interface PrettyCustomViewTableViewCell : PrettyTableViewCell

/** Holds a reference to the custom view. */
@property (nonatomic, retain) UIView *customView;
@property (nonatomic) UIView *customView;

@end
6 changes: 0 additions & 6 deletions PrettyKit/Cells/PrettyCustomViewTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ @implementation PrettyCustomViewTableViewCell

#define shadow_margin 4

- (void) dealloc
{
self.customView = nil;

[super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
Expand Down
4 changes: 2 additions & 2 deletions PrettyKit/Cells/PrettyGridTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
25 changes: 2 additions & 23 deletions PrettyKit/Cells/PrettyGridTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
{
Expand Down Expand Up @@ -313,7 +307,6 @@ - (void) deselectAnimated:(BOOL)animated completion:(void (^)(void))block
}
completion:^(BOOL finished) {
[imageView removeFromSuperview];
[imageView release];
if (block) {
block();
}
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PrettyKit/Cells/PrettySegmentedControlTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
@interface PrettySegmentedControlTableViewCell : PrettyGridTableViewCell


@property (nonatomic, retain) NSArray *titles;
@property (nonatomic) NSArray *titles;
@property (nonatomic, assign) NSInteger selectedIndex;

@end
3 changes: 1 addition & 2 deletions PrettyKit/Cells/PrettySegmentedControlTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions PrettyKit/Cells/PrettyTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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.
Expand All @@ -171,15 +171,15 @@ 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.

This property has a blue color by default.

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 */
Expand Down Expand Up @@ -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;
Expand Down
50 changes: 30 additions & 20 deletions PrettyKit/Cells/PrettyTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -315,7 +315,6 @@ - (void) dealloc
{
self.cell = nil;

[super dealloc];
}

- (id) initWithFrame:(CGRect)frame behavior:(CellBackgroundBehavior)bbehavior
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -388,19 +379,39 @@ - (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];
}
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
{
Expand Down Expand Up @@ -492,10 +503,6 @@ - (void) prepareForReuse

- (void) setTableViewBackgroundColor:(UIColor *)aBackgroundColor
{
[aBackgroundColor retain];
if (tableViewBackgroundColor != nil) {
[tableViewBackgroundColor release];
}
tableViewBackgroundColor = aBackgroundColor;

self.backgroundView.backgroundColor = aBackgroundColor;
Expand Down Expand Up @@ -569,7 +576,7 @@ - (CAShapeLayer *) mask
maskLayer.frame = maskRect;
maskLayer.path = maskPath.CGPath;

return [maskLayer autorelease];
return maskLayer;
}

- (BOOL) dropsShadow
Expand Down Expand Up @@ -599,7 +606,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;
Expand All @@ -617,12 +624,15 @@ - (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;
}


- (void) dealloc
{
[self.contentView removeObserver:self forKeyPath:@"frame" context:nil];
}

@end
9 changes: 9 additions & 0 deletions PrettyKit/PrettyDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
40 changes: 36 additions & 4 deletions PrettyKit/PrettyDrawing.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -42,12 +76,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));
Expand Down
Loading