Skip to content

Commit

Permalink
Cleaned up ivars and removed switch cell
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Mar 12, 2010
1 parent 47cb041 commit 6a23e1d
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 203 deletions.
8 changes: 0 additions & 8 deletions TWToolkit.xcodeproj/project.pbxproj
Expand Up @@ -31,8 +31,6 @@
B2974D75106299CB00C9F4A6 /* UIImage+crop.m in Sources */ = {isa = PBXBuildFile; fileRef = B2974D64106299CB00C9F4A6 /* UIImage+crop.m */; };
B2974D78106299CB00C9F4A6 /* UIView+fading.h in Headers */ = {isa = PBXBuildFile; fileRef = B2974D67106299CB00C9F4A6 /* UIView+fading.h */; };
B2974D79106299CB00C9F4A6 /* UIView+fading.m in Sources */ = {isa = PBXBuildFile; fileRef = B2974D68106299CB00C9F4A6 /* UIView+fading.m */; };
B2A41E9A107287BA006EF521 /* TWSwitchTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A41E98107287BA006EF521 /* TWSwitchTableViewCell.h */; };
B2A41E9B107287BA006EF521 /* TWSwitchTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = B2A41E99107287BA006EF521 /* TWSwitchTableViewCell.m */; };
B2C20770106296FB00AE1B56 /* NSArray+shuffle.h in Headers */ = {isa = PBXBuildFile; fileRef = B2C20766106296FB00AE1B56 /* NSArray+shuffle.h */; };
B2C20771106296FB00AE1B56 /* NSArray+shuffle.m in Sources */ = {isa = PBXBuildFile; fileRef = B2C20767106296FB00AE1B56 /* NSArray+shuffle.m */; };
B2C20772106296FB00AE1B56 /* NSData+MD5Sum.h in Headers */ = {isa = PBXBuildFile; fileRef = B2C20768106296FB00AE1B56 /* NSData+MD5Sum.h */; };
Expand Down Expand Up @@ -79,8 +77,6 @@
B2974D64106299CB00C9F4A6 /* UIImage+crop.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+crop.m"; sourceTree = "<group>"; };
B2974D67106299CB00C9F4A6 /* UIView+fading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+fading.h"; sourceTree = "<group>"; };
B2974D68106299CB00C9F4A6 /* UIView+fading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+fading.m"; sourceTree = "<group>"; };
B2A41E98107287BA006EF521 /* TWSwitchTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TWSwitchTableViewCell.h; sourceTree = "<group>"; };
B2A41E99107287BA006EF521 /* TWSwitchTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TWSwitchTableViewCell.m; sourceTree = "<group>"; };
B2C20766106296FB00AE1B56 /* NSArray+shuffle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+shuffle.h"; sourceTree = "<group>"; };
B2C20767106296FB00AE1B56 /* NSArray+shuffle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+shuffle.m"; sourceTree = "<group>"; };
B2C20768106296FB00AE1B56 /* NSData+MD5Sum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+MD5Sum.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -193,8 +189,6 @@
B2A41E97107287A5006EF521 /* Cells */ = {
isa = PBXGroup;
children = (
B2A41E98107287BA006EF521 /* TWSwitchTableViewCell.h */,
B2A41E99107287BA006EF521 /* TWSwitchTableViewCell.m */,
B2C6829B114954DB006EDD71 /* TWMessageTableViewCell.h */,
B2C6829C114954DB006EDD71 /* TWMessageTableViewCell.m */,
);
Expand Down Expand Up @@ -277,7 +271,6 @@
B2974D78106299CB00C9F4A6 /* UIView+fading.h in Headers */,
B28517DA1063E43E008D42E7 /* TWPickerViewController.h in Headers */,
B28517E01063E442008D42E7 /* TWLoadingView.h in Headers */,
B2A41E9A107287BA006EF521 /* TWSwitchTableViewCell.h in Headers */,
B253C1FA10728DC500E0CE10 /* TWHUDView.h in Headers */,
B2503B9510A90DA6009B0E7B /* TWGradientView.h in Headers */,
B24B551810B36F6B0014994C /* UIImage+BundleImage.h in Headers */,
Expand Down Expand Up @@ -345,7 +338,6 @@
B2974D79106299CB00C9F4A6 /* UIView+fading.m in Sources */,
B28517DB1063E43E008D42E7 /* TWPickerViewController.m in Sources */,
B28517E11063E442008D42E7 /* TWLoadingView.m in Sources */,
B2A41E9B107287BA006EF521 /* TWSwitchTableViewCell.m in Sources */,
B253C1FB10728DC500E0CE10 /* TWHUDView.m in Sources */,
B2503B9610A90DA6009B0E7B /* TWGradientView.m in Sources */,
B24B551910B36F6B0014994C /* UIImage+BundleImage.m in Sources */,
Expand Down
24 changes: 11 additions & 13 deletions TWToolkit/TWGradientView.h
Expand Up @@ -19,22 +19,20 @@
// conversions are planned for the future.
//

#import <UIKit/UIKit.h>

@interface TWGradientView : UIView {

UIColor *topColor;
UIColor *bottomColor;
UIColor *topBorderColor;
UIColor *bottomBorderColor;
CGFloat topInsetAlpha;
CGFloat bottomInsetAlpha;
BOOL hasTopBorder;
BOOL hasBottomBorder;
BOOL showsInsets;
UIColor *_topColor;
UIColor *_bottomColor;
UIColor *_topBorderColor;
UIColor *_bottomBorderColor;
CGFloat _topInsetAlpha;
CGFloat _bottomInsetAlpha;
BOOL _hasTopBorder;
BOOL _hasBottomBorder;
BOOL _showsInsets;

BOOL hasDrawn;
CGGradientRef gradient;
BOOL _hasDrawn;
CGGradientRef _gradient;
}

@property (nonatomic, retain) UIColor *topColor;
Expand Down
56 changes: 28 additions & 28 deletions TWToolkit/TWGradientView.m
Expand Up @@ -17,15 +17,15 @@ - (void)_refreshGradient;

@implementation TWGradientView

@synthesize topColor;
@synthesize bottomColor;
@synthesize topBorderColor;
@synthesize bottomBorderColor;
@synthesize topInsetAlpha;
@synthesize bottomInsetAlpha;
@synthesize hasTopBorder;
@synthesize hasBottomBorder;
@synthesize showsInsets;
@synthesize topColor = _topColor;
@synthesize bottomColor = _bottomColor;
@synthesize topBorderColor = _topBorderColor;
@synthesize bottomBorderColor = _bottomBorderColor;
@synthesize topInsetAlpha = _topInsetAlpha;
@synthesize bottomInsetAlpha = _bottomInsetAlpha;
@synthesize hasTopBorder = _hasTopBorder;
@synthesize hasBottomBorder = _hasBottomBorder;
@synthesize showsInsets = _showsInsets;

#pragma mark -
#pragma mark Class Methods
Expand Down Expand Up @@ -66,7 +66,7 @@ + (CGFloat)defaultBottomInsetAlpha {
#pragma mark -

- (void)dealloc {
if (hasDrawn) {
if (_hasDrawn) {
[self removeObserver:self forKeyPath:@"topColor"];
[self removeObserver:self forKeyPath:@"bottomColor"];
[self removeObserver:self forKeyPath:@"topBorderColor"];
Expand All @@ -76,7 +76,7 @@ - (void)dealloc {
[self removeObserver:self forKeyPath:@"hasTopBorder"];
[self removeObserver:self forKeyPath:@"hasBottomBorder"];
[self removeObserver:self forKeyPath:@"showsInsets"];
CGGradientRelease(gradient);
CGGradientRelease(_gradient);
}
self.topColor = nil;
self.bottomColor = nil;
Expand Down Expand Up @@ -105,15 +105,15 @@ - (id)initWithFrame:(CGRect)frame {
self.hasBottomBorder = YES;
self.showsInsets = YES;

hasDrawn = NO;
gradient = nil;
_hasDrawn = NO;
_gradient = nil;
}
return self;
}


- (void)drawRect:(CGRect)rect {
if (!hasDrawn) {
if (!_hasDrawn) {
// Add observers
[self addObserver:self forKeyPath:@"topColor" options:NSKeyValueObservingOptionNew context:nil];
[self addObserver:self forKeyPath:@"bottomColor" options:NSKeyValueObservingOptionNew context:nil];
Expand All @@ -128,7 +128,7 @@ - (void)drawRect:(CGRect)rect {
// Draw gradient
[self _refreshGradient];

hasDrawn = YES;
_hasDrawn = YES;
}

CGContextRef context = UIGraphicsGetCurrentContext();
Expand All @@ -138,37 +138,37 @@ - (void)drawRect:(CGRect)rect {
// Gradient
CGPoint start = CGPointMake(0.0, 0.0);
CGPoint end = CGPointMake(0.0, rect.size.height);
CGContextDrawLinearGradient(context, gradient, start, end, 0);
CGContextDrawLinearGradient(context, _gradient, start, end, 0);

CGContextSetLineWidth(context, 2.0);

if (hasTopBorder) {
if (_hasTopBorder) {
// Top inset
if (showsInsets && topInsetAlpha > 0.0) {
CGContextSetStrokeColorWithColor(context, [UIColor colorWithWhite:1.0 alpha:topInsetAlpha].CGColor);
if (_showsInsets && _topInsetAlpha > 0.0) {
CGContextSetStrokeColorWithColor(context, [UIColor colorWithWhite:1.0 alpha:_topInsetAlpha].CGColor);
CGContextMoveToPoint(context, 0.0, 1.0);
CGContextAddLineToPoint(context, rect.size.width, 1.0);
CGContextStrokePath(context);
}

// Top border
CGContextSetStrokeColorWithColor(context, topBorderColor.CGColor);
CGContextSetStrokeColorWithColor(context, _topBorderColor.CGColor);
CGContextMoveToPoint(context, 0.0, 0.0);
CGContextAddLineToPoint(context, rect.size.width, 0.0);
CGContextStrokePath(context);
}

if (hasBottomBorder) {
if (_hasBottomBorder) {
// Bottom inset
if (showsInsets && bottomInsetAlpha > 0.0) {
CGContextSetStrokeColorWithColor(context, [UIColor colorWithWhite:1.0 alpha:bottomInsetAlpha].CGColor);
if (_showsInsets && _bottomInsetAlpha > 0.0) {
CGContextSetStrokeColorWithColor(context, [UIColor colorWithWhite:1.0 alpha:_bottomInsetAlpha].CGColor);
CGContextMoveToPoint(context, 0.0, rect.size.height - 1.0);
CGContextAddLineToPoint(context, rect.size.width, rect.size.height - 1.0);
CGContextStrokePath(context);
}

// Bottom border
CGContextSetStrokeColorWithColor(context, bottomBorderColor.CGColor);
CGContextSetStrokeColorWithColor(context, _bottomBorderColor.CGColor);
CGContextMoveToPoint(context, 0.0, rect.size.height);
CGContextAddLineToPoint(context, rect.size.width, rect.size.height);
CGContextStrokePath(context);
Expand All @@ -182,10 +182,10 @@ - (void)drawRect:(CGRect)rect {

- (void)_refreshGradient {
// TODO: Automatically convert colors into the same colorspace
CGColorSpaceRef colorSpace = CGColorGetColorSpace(topColor.CGColor);
NSArray *colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
CGGradientRelease(gradient);
gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)colors, NULL);
CGColorSpaceRef colorSpace = CGColorGetColorSpace(_topColor.CGColor);
NSArray *colors = [NSArray arrayWithObjects:(id)_topColor.CGColor, (id)_bottomColor.CGColor, nil];
CGGradientRelease(_gradient);
_gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)colors, NULL);
[self setNeedsDisplay];
}

Expand Down
10 changes: 5 additions & 5 deletions TWToolkit/TWHUDView.h
Expand Up @@ -8,13 +8,13 @@

@interface TWHUDView : UIAlertView {

UILabel *textLabel;
UIActivityIndicatorView *activityIndicator;
BOOL loading;
UILabel *_textLabel;
UIActivityIndicatorView *_activityIndicator;
BOOL _loading;
}

@property (nonatomic, retain) UILabel *textLabel;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, retain, readonly) UILabel *textLabel;
@property (nonatomic, retain, readonly) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, assign, getter=isLoading) BOOL loading;

- (id)initWithTitle:(NSString *)aTitle;
Expand Down
57 changes: 28 additions & 29 deletions TWToolkit/TWHUDView.m
Expand Up @@ -10,13 +10,14 @@
#import "UIImage+BundleImage.h"
#import <QuartzCore/QuartzCore.h>

#define kHUDSize 172.0
static CGFloat kHUDSize = 172.0;
static CGFloat kIndicatorSize = 40.0;

@implementation TWHUDView

@synthesize textLabel;
@synthesize activityIndicator;
@synthesize loading;
@synthesize textLabel = _textLabel;
@synthesize activityIndicator = _activityIndicator;
@synthesize loading = _loading;

#pragma mark -
#pragma mark NSObject
Expand All @@ -28,8 +29,8 @@ - (id)init {


- (void)dealloc {
[activityIndicator release];
[textLabel release];
[_activityIndicator release];
[_textLabel release];
[super dealloc];
}

Expand Down Expand Up @@ -66,18 +67,16 @@ - (void)drawRect:(CGRect)rect {
CGContextFillPath(context);

// Checkmark
if (loading == NO) {
if (_loading == NO) {
UIImage *checkmark = [UIImage imageNamed:@"images/hud-checkmark.png" bundle:@"TWToolkit.bundle"];
[checkmark drawInRect:CGRectMake(round((kHUDSize - 36.0) / 2.0), round((kHUDSize - 40.0) / 2.0), 36.0, 40.0)];
}
}


- (void)layoutSubviews {
static CGFloat indicatorSize = 40.0;

activityIndicator.frame = CGRectMake(round((kHUDSize - indicatorSize) / 2.0), round((kHUDSize - indicatorSize) / 2.0), indicatorSize, indicatorSize);
textLabel.frame = CGRectMake(0.0, round(kHUDSize - 30.0), kHUDSize, 20.0);
_activityIndicator.frame = CGRectMake(round((kHUDSize - kIndicatorSize) / 2.0), round((kHUDSize - kIndicatorSize) / 2.0), kIndicatorSize, kIndicatorSize);
_textLabel.frame = CGRectMake(0.0, round(kHUDSize - 30.0), kHUDSize, 20.0);
}


Expand All @@ -97,7 +96,7 @@ - (void)show {

// Deprecated. Overridding UIAlertView's setTitle.
- (void)setTitle:(NSString *)aTitle {
textLabel.text = aTitle;
_textLabel.text = aTitle;
}

#pragma mark -
Expand All @@ -112,22 +111,22 @@ - (id)initWithTitle:(NSString *)aTitle {
- (id)initWithTitle:(NSString *)aTitle loading:(BOOL)isLoading {
if (self = [super initWithFrame:CGRectZero]) {
// Indicator
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.alpha = 0.0;
[activityIndicator startAnimating];
[self addSubview:activityIndicator];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activityIndicator.alpha = 0.0;
[_activityIndicator startAnimating];
[self addSubview:_activityIndicator];

// Text Label
textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
textLabel.font = [UIFont boldSystemFontOfSize:14];
textLabel.backgroundColor = [UIColor clearColor];
textLabel.textColor = [UIColor whiteColor];
textLabel.shadowColor = [UIColor blackColor];
textLabel.shadowOffset = CGSizeMake(0.0, 1.0);
textLabel.textAlignment = UITextAlignmentCenter;
textLabel.lineBreakMode = UILineBreakModeTailTruncation;
textLabel.text = aTitle ? aTitle : @"Loading";
[self addSubview:textLabel];
_textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_textLabel.font = [UIFont boldSystemFontOfSize:14];
_textLabel.backgroundColor = [UIColor clearColor];
_textLabel.textColor = [UIColor whiteColor];
_textLabel.shadowColor = [UIColor blackColor];
_textLabel.shadowOffset = CGSizeMake(0.0, 1.0);
_textLabel.textAlignment = UITextAlignmentCenter;
_textLabel.lineBreakMode = UILineBreakModeTailTruncation;
_textLabel.text = aTitle ? aTitle : @"Loading";
[self addSubview:_textLabel];

// Loading
self.loading = isLoading;
Expand All @@ -138,7 +137,7 @@ - (id)initWithTitle:(NSString *)aTitle loading:(BOOL)isLoading {

- (void)completeWithTitle:(NSString *)aTitle {
self.loading = NO;
textLabel.text = aTitle;
_textLabel.text = aTitle;
}


Expand All @@ -163,8 +162,8 @@ - (void)dismissAnimated:(BOOL)animated {
#pragma mark -

- (void)setLoading:(BOOL)isLoading {
loading = isLoading;
activityIndicator.alpha = loading ? 1.0 : 0.0;
_loading = isLoading;
_activityIndicator.alpha = _loading ? 1.0 : 0.0;
[self setNeedsDisplay];

}
Expand Down
20 changes: 10 additions & 10 deletions TWToolkit/TWLoadingView.h
Expand Up @@ -8,17 +8,17 @@

@interface TWLoadingView : UIView {

UIActivityIndicatorView *indicator;
NSString *text;
UIFont *font;
UIColor *textColor;
UIColor *shadowColor;
UIActivityIndicatorView *_activityIndicator;
NSString *_text;
UIFont *_font;
UIColor *_textColor;
UIColor *_shadowColor;
}

@property (nonatomic, retain) UIActivityIndicatorView *indicator;
@property (nonatomic, retain) NSString *text;
@property (nonatomic, retain) UIFont *font;
@property (nonatomic, retain) UIColor *textColor;
@property (nonatomic, retain) UIColor *shadowColor;
@property (nonatomic, retain, readonly) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, copy) NSString *text;
@property (nonatomic, copy) UIFont *font;
@property (nonatomic, copy) UIColor *textColor;
@property (nonatomic, copy) UIColor *shadowColor;

@end

0 comments on commit 6a23e1d

Please sign in to comment.