Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 3cf09b8fdb15c6cb2073bd5994d9d30d1438ecda 0 parents
@soffes soffes authored
Showing with 197 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +6 −0 Readme.markdown
  3. +48 −0 SSIndicatorLabel.h
  4. +123 −0 SSIndicatorLabel.m
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010-2011 Sam Soffes
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 Readme.markdown
@@ -0,0 +1,6 @@
+# SSIndicatorLabel
+
+This view was abstracted from [SSToolkit](https://github.com/samsoffes/sstoolkit).
+
+It displays an indicator to the left when something is load and animates it away when it stops loading.
+
48 SSIndicatorLabel.h
@@ -0,0 +1,48 @@
+//
+// SSIndicatorLabel.h
+// SSIndicatorLabel
+//
+// Created by Sam Soffes on 7/13/10.
+// Copyright 2010-2011 Sam Soffes. All rights reserved.
+//
+
+/**
+ This class is a nice little view that makes showing an activity indicator next to a label when loading something easy.
+
+ The indicator will slide in from the left when loading and then back out when it is complete. This is great for a view
+ that shows some sort of status that can refresh.
+ */
+@interface SSIndicatorLabel : UIView
+
+/**
+ Returns the label used for the main textual content of the view. (read-only)
+ */
+@property (nonatomic, retain, readonly) UILabel *textLabel;
+
+/**
+ A view that indicates loading activity to the user. (read-only)
+ */
+@property (nonatomic, retain, readonly) UIActivityIndicatorView *activityIndicatorView;
+
+/**
+ A Boolean value that determines whether the view is loading.
+
+ The default value is `NO`.
+ */
+@property (nonatomic, assign, getter=isLoading) BOOL loading;
+
+/**
+ Starts loading and updates the text of the text label.
+
+ @param text String to update the `textLabel`'s `text` property to.
+ */
+- (void)startWithText:(NSString *)text;
+
+/**
+ Completes loading and updates the text of the text label.
+
+ @param text String to update the `textLabel`'s `text` property to.
+ */
+- (void)completeWithText:(NSString *)text;
+
+@end
123 SSIndicatorLabel.m
@@ -0,0 +1,123 @@
+//
+// SSIndicatorLabel.m
+// SSIndicatorLabel
+//
+// Created by Sam Soffes on 7/13/10.
+// Copyright 2010-2011 Sam Soffes. All rights reserved.
+//
+
+#import "SSIndicatorLabel.h"
+
+@interface SSIndicatorLabel (PrivateMethods)
++ (CGSize)indicatorSize;
++ (CGFloat)padding;
+@end
+
+@implementation SSIndicatorLabel
+
+#pragma mark - Accessors
+
+@synthesize textLabel = _textLabel;
+@synthesize activityIndicatorView = _activityIndicatorView;
+
+@synthesize loading = _loading;
+
+- (void)setLoading:(BOOL)l {
+ if (_loading == l) {
+ return;
+ }
+
+ [UIView beginAnimations:@"loading" context:nil];
+ _loading = l;
+ [self layoutSubviews];
+ [UIView commitAnimations];
+}
+
+
+#pragma mark - Class Methods
+
++ (CGSize)indicatorSize {
+ return CGSizeMake(20.0f, 20.0f);
+}
+
+
++ (CGFloat)padding {
+ return 6.0f;
+}
+
+
+#pragma mark - NSObject
+
+- (void)dealloc {
+ [_textLabel release];
+ [_activityIndicatorView release];
+ [super dealloc];
+}
+
+
+#pragma mark - UIView
+
+- (id)initWithFrame:(CGRect)rect {
+ if ((self = [super initWithFrame:rect])) {
+ self.clipsToBounds = YES;
+
+ _textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
+ [self addSubview:_textLabel];
+
+ _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectZero];
+ [_activityIndicatorView startAnimating];
+ [self addSubview:_activityIndicatorView];
+
+ _loading = NO;
+ [self layoutSubviews];
+ }
+ return self;
+}
+
+
+- (void)layoutSubviews {
+ CGRect rect = self.frame;
+ CGSize size = [[self class] indicatorSize];
+ CGFloat x = size.width + [[self class] padding];
+
+ // Loading
+ if (_loading) {
+ _textLabel.frame = CGRectMake(x, 0.0f, rect.size.width - x, size.height);
+ _activityIndicatorView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
+ }
+
+ // Not loading
+ else {
+ _textLabel.frame = CGRectMake(0.0f, 0.0f, rect.size.width, size.height);
+ _activityIndicatorView.frame = CGRectMake(-x, 0.0f, size.width, size.height);
+ }
+}
+
+
+- (void)setBackgroundColor:(UIColor *)color {
+ [super setBackgroundColor:color];
+ _textLabel.backgroundColor = color;
+ _activityIndicatorView.backgroundColor = color;
+}
+
+
+- (void)setOpaque:(BOOL)o {
+ [super setOpaque:o];
+ _textLabel.opaque = o;
+ _activityIndicatorView.opaque = o;
+}
+
+
+#pragma mark - Status
+
+- (void)startWithText:(NSString *)text {
+ self.loading = YES;
+ _textLabel.text = text;
+}
+
+- (void)completeWithText:(NSString *)text {
+ self.loading = NO;
+ _textLabel.text = text;
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.