Created
July 8, 2009 16:51
-
-
Save soffes/142965 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// LoadingView.h | |
// | |
// Created by Sam Soffes on 7/8/09. | |
// Copyright 2009 Sam Soffes. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface LoadingView : UIView { | |
UIActivityIndicatorView *indicator; | |
NSString *text; | |
UIFont *font; | |
UIColor *color; | |
UIColor *shadowColor; | |
} | |
@property (nonatomic, retain) UIActivityIndicatorView *indicator; | |
@property (nonatomic, retain) NSString *text; | |
@property (nonatomic, retain) UIFont *font; | |
@property (nonatomic, retain) UIColor *color; | |
@property (nonatomic, retain) UIColor *shadowColor; | |
@end |
This file contains hidden or 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
// | |
// LoadingView.m | |
// PushTweet | |
// | |
// Created by Sam Soffes on 7/8/09. | |
// Copyright 2009 Trimonix LLC. All rights reserved. | |
// | |
#import "LoadingView.h" | |
@implementation LoadingView | |
@synthesize indicator; | |
@synthesize text; | |
@synthesize font; | |
@synthesize color; | |
@synthesize shadowColor; | |
- (id)initWithFrame:(CGRect)frame { | |
if (self = [super initWithFrame:frame]) { | |
// View defaults | |
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
self.backgroundColor = [UIColor clearColor]; | |
self.opaque = NO; | |
// Setup the indicator | |
indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; | |
indicator.hidesWhenStopped = NO; | |
[indicator startAnimating]; | |
[self addSubview:indicator]; | |
// Defaults | |
self.text = @"Loading..."; | |
self.font = [UIFont systemFontOfSize:16.0]; | |
self.color = [UIColor whiteColor]; | |
self.shadowColor = [UIColor blackColor]; | |
} | |
return self; | |
} | |
- (void)drawRect:(CGRect)rect { | |
// Indicator is 20px x 20px | |
// There are 8px of space between the indicator and the text | |
CGSize maxSize = CGSizeMake(self.frame.size.width - 68.0, 20.0); | |
CGSize textSize = [text sizeWithFont:font constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap]; | |
CGFloat totalWidth = textSize.width + 28.0; | |
NSInteger y = (NSInteger)((self.frame.size.height / 2.0) - 10.0); | |
indicator.frame = CGRectMake((NSInteger)((self.frame.size.width - totalWidth) / 2.0), y, 20.0, 20.0); | |
CGRect textRect = CGRectMake(indicator.frame.origin.x + 28.0, y, textSize.width, textSize.height); | |
// Shadow | |
// The offset is (0, 1) | |
[shadowColor set]; | |
CGRect shadowRect = CGRectMake(textRect.origin.x, textRect.origin.y + 1.0, textRect.size.width, textRect.size.height); | |
[text drawInRect:shadowRect withFont:font lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft]; | |
// Text | |
[color set]; | |
[text drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft]; | |
} | |
- (void)dealloc { | |
[font release]; | |
[color release]; | |
[shadowColor release]; | |
[indicator release]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment