Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert SSLoadingView to use UILabel as its model. Fixes #75

  • Loading branch information...
commit b8b2d76fc5ae8d7053089391988d395c24161303 1 parent 5599010
Sam Soffes soffes authored
Showing with 24 additions and 104 deletions.
  1. +4 −34 SSToolkit/SSLoadingView.h
  2. +20 −70 SSToolkit/SSLoadingView.m
38 SSToolkit/SSLoadingView.h
View
@@ -15,43 +15,13 @@
@interface SSLoadingView : UIView
/**
- A view that indicates loading activity to the user. (read-only)
- */
-@property (nonatomic, retain, readonly) UIActivityIndicatorView *activityIndicatorView;
-
-/**
- The text that is displayed to the user.
-
- The default is "Loading..."
- */
-@property (nonatomic, copy) NSString *text;
-
-/**
- The font of the `text`.
- */
-@property (nonatomic, retain) UIFont *font;
-
-/**
- The color of the text.
-
- The default value is `[UIColor darkGrayColor]`.
- */
-@property (nonatomic, retain) UIColor *textColor;
-
-/**
- The color of the text shadow.
-
- Set to `nil` to disable drawing the shadow. The default value is `[UIColor whiteColor]`.
+ The text label that is displayed to the user.
*/
-@property (nonatomic, retain) UIColor *shadowColor;
+@property (nonatomic, retain, readonly) UILabel *textLabel;
/**
- The shadow offset (measured in points) for the `text`.
-
- The `shadowColor` must be non-nil for this property to have any effect. The default offset size is (0, 1), which
- indicates a shadow one point below the text. Text shadows are drawn with the specified offset and color and no
- blurring.
+ A view that indicates loading activity to the user. (read-only)
*/
-@property (nonatomic, assign) CGSize shadowOffset;
+@property (nonatomic, retain, readonly) UIActivityIndicatorView *activityIndicatorView;
@end
90 SSToolkit/SSLoadingView.m
View
@@ -16,64 +16,14 @@ @implementation SSLoadingView
#pragma mark - Accessors
+@synthesize textLabel = _textLabel;
@synthesize activityIndicatorView = _activityIndicatorView;
-@synthesize text = _text;
-
-- (void)setText:(NSString *)text {
- [_text release];
- _text = [text copy];
-
- [self setNeedsDisplay];
-}
-
-
-@synthesize font = _font;
-
-- (void)setFont:(UIFont *)font {
- [_font release];
- _font = [font retain];
-
- [self setNeedsDisplay];
-}
-
-
-@synthesize textColor = _textColor;
-
-- (void)setTextColor:(UIColor *)textColor {
- [_textColor release];
- _textColor = [textColor retain];
-
- [self setNeedsDisplay];
-}
-
-
-@synthesize shadowColor = _shadowColor;
-
-- (void)setShadowColor:(UIColor *)shadowColor {
- [_shadowColor release];
- _shadowColor = [shadowColor retain];
-
- [self setNeedsDisplay];
-}
-
-
-@synthesize shadowOffset = _shadowOffset;
-
-- (void)setShadowOffset:(CGSize)shadowOffset {
- _shadowOffset = shadowOffset;
-
- [self setNeedsDisplay];
-}
-
#pragma mark - NSObject
- (void)dealloc {
- [_font release];
- [_text release];
- [_textColor release];
- [_shadowColor release];
+ [_textLabel release];
[_activityIndicatorView release];
[super dealloc];
}
@@ -90,6 +40,9 @@ - (id)initWithFrame:(CGRect)frame {
self.opaque = YES;
self.contentMode = UIViewContentModeRedraw;
+ // Setup label
+ _textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
+
// Setup the indicator
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_activityIndicatorView.hidesWhenStopped = NO;
@@ -97,11 +50,11 @@ - (id)initWithFrame:(CGRect)frame {
[self addSubview:_activityIndicatorView];
// Defaults
- self.text = @"Loading...";
- self.font = [UIFont systemFontOfSize:16.0f];
- self.textColor = [UIColor darkGrayColor];
- self.shadowColor = [UIColor whiteColor];
- _shadowOffset = CGSizeMake(0.0f, 1.0f);
+ _textLabel.text = @"Loading...";
+ _textLabel.font = [UIFont systemFontOfSize:16.0f];
+ _textLabel.textColor = [UIColor darkGrayColor];
+ _textLabel.shadowColor = [UIColor whiteColor];
+ _textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
}
return self;
}
@@ -112,29 +65,26 @@ - (void)drawRect:(CGRect)rect {
CGRect frame = self.frame;
// Calculate sizes
- CGSize maxSize = CGSizeMake(frame.size.width - (interiorPadding * 2.0f) - indicatorSize - indicatorRightMargin, indicatorSize);
- CGSize textSize = [_text sizeWithFont:_font constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap];
+ CGSize maxSize = CGSizeMake(frame.size.width - (interiorPadding * 2.0f) - indicatorSize - indicatorRightMargin,
+ indicatorSize);
+
+ CGSize textSize = [_textLabel.text sizeWithFont:_textLabel.font constrainedToSize:maxSize
+ lineBreakMode:UILineBreakModeWordWrap];
// Calculate position
CGFloat totalWidth = textSize.width + indicatorSize + indicatorRightMargin;
NSInteger y = (NSInteger)((frame.size.height / 2.0f) - (indicatorSize / 2.0f));
// Position the indicator
- _activityIndicatorView.frame = CGRectMake((NSInteger)((frame.size.width - totalWidth) / 2.0f), y, indicatorSize, indicatorSize);
+ _activityIndicatorView.frame = CGRectMake((NSInteger)((frame.size.width - totalWidth) / 2.0f), y, indicatorSize,
+ indicatorSize);
// Calculate text position
- CGRect textRect = CGRectMake(_activityIndicatorView.frame.origin.x + indicatorSize + indicatorRightMargin, y, textSize.width, textSize.height);
-
- // Draw shadow
- if (_shadowColor) {
- [_shadowColor set];
- CGRect shadowRect = CGRectMake(textRect.origin.x + _shadowOffset.width, textRect.origin.y + _shadowOffset.height, textRect.size.width, textRect.size.height);
- [_text drawInRect:shadowRect withFont:_font lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft];
- }
+ CGRect textRect = CGRectMake(_activityIndicatorView.frame.origin.x + indicatorSize + indicatorRightMargin, y,
+ textSize.width, textSize.height);
// Draw text
- [_textColor set];
- [_text drawInRect:textRect withFont:_font lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft];
+ [_textLabel drawTextInRect:textRect];
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.