Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove self from NSNotificationCenter's Observers #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions KGStatusBar/KGStatusBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@interface KGStatusBar : UIView

+ (void)showWithStatus:(NSString*)status;
+ (void)showLoadingWithStatus:(NSString*)status;
+ (void)showErrorWithStatus:(NSString*)status;
+ (void)showSuccessWithStatus:(NSString*)status;
+ (void)dismiss;
Expand Down
28 changes: 27 additions & 1 deletion KGStatusBar/KGStatusBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ @interface KGStatusBar ()
@property (nonatomic, strong, readonly) UIWindow *overlayWindow;
@property (nonatomic, strong, readonly) UIView *topBar;
@property (nonatomic, strong) UILabel *stringLabel;
@property (nonatomic, strong) UIActivityIndicatorView *spinner;
@end

@implementation KGStatusBar
Expand All @@ -31,6 +32,12 @@ + (void)showSuccessWithStatus:(NSString*)status
[KGStatusBar performSelector:@selector(dismiss) withObject:self afterDelay:2.0 ];
}

+(void)showLoadingWithStatus:(NSString *)status
{
[[KGStatusBar sharedView] showWithStatus:status barColor:[UIColor blackColor] textColor:[UIColor colorWithRed:191.0/255.0 green:191.0/255.0 blue:191.0/255.0 alpha:1.0]];
[[KGStatusBar sharedView].spinner startAnimating];
}

+ (void)showWithStatus:(NSString*)status {
[[KGStatusBar sharedView] showWithStatus:status barColor:[UIColor blackColor] textColor:[UIColor colorWithRed:191.0/255.0 green:191.0/255.0 blue:191.0/255.0 alpha:1.0]];
}
Expand All @@ -55,7 +62,13 @@ - (id)initWithFrame:(CGRect)frame {
return self;
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)showWithStatus:(NSString *)status barColor:(UIColor*)barColor textColor:(UIColor*)textColor{
[_spinner stopAnimating];
if(!self.superview)
[self.overlayWindow addSubview:self];
[self.overlayWindow setHidden:NO];
Expand Down Expand Up @@ -90,7 +103,8 @@ - (void) dismiss
} completion:^(BOOL finished) {
[topBar removeFromSuperview];
topBar = nil;

[_spinner removeFromSuperview];
_spinner = nil;
[overlayWindow removeFromSuperview];
overlayWindow = nil;
}];
Expand Down Expand Up @@ -151,6 +165,18 @@ - (UILabel *)stringLabel {
return stringLabel;
}

-(UIActivityIndicatorView *)spinner
{
if (_spinner == nil)
{
_spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
_spinner.center = CGPointMake(CGRectGetMinX(self.stringLabel.frame) - 25, self.stringLabel.center.y);
[_spinner setHidesWhenStopped:YES];
[self.topBar addSubview:_spinner];
}
return _spinner;
}

#pragma mark - Handle Rotation

- (CGFloat)rotation
Expand Down
2 changes: 1 addition & 1 deletion KGStatusBarExample/KGStatusBarExample/KGViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (IBAction)errorButtonPressed:(id)sender {
}

- (IBAction)statusButtonPressed:(id)sender {
[KGStatusBar showWithStatus:@"Loading..."];
[KGStatusBar showLoadingWithStatus:@"Loading..."];
}

- (IBAction)dismissButtonPressed:(id)sender {
Expand Down