Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 91e6a4f08b404cdcce2536cbd3ee1f4d39804c67 @frankdilo committed Sep 6, 2012
@@ -0,0 +1,38 @@
+//
+// StatusBarNotifierView.h
+// StatusBarNotifier
+//
+// Created by Francesco Di Lorenzo on 05/09/12.
+// Copyright (c) 2012 Francesco Di Lorenzo. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+
+
+@interface FDStatusBarNotifierView : UIView
+
+@property (strong, nonatomic) NSString *message;
+@property NSTimeInterval timeOnScreen; // seconds, default: 2s
+@property id delegate;
+
+
+- (id)initWithMessage:(NSString *)message;
+- (id)initWithMessage:(NSString *)message delegate:(id /*<StatusBarNotifierViewDelegate>*/)delegate;
+
+- (void)showInWindow:(UIWindow *)window;
+
+@end
+
+
+@protocol StatusBarNotifierViewDelegate <NSObject>
+@optional
+
+- (void)willPresentNotifierView:(FDStatusBarNotifierView *)notifierView; // before animation and showing view
+- (void)didPresentNotifierView:(FDStatusBarNotifierView *)notifierView; // after animation
+- (void)willHideNotifierView:(FDStatusBarNotifierView *)notifierView; // before hiding animation
+- (void)didHideNotifierView:(FDStatusBarNotifierView *)notifierView; // after animation
+
+- (void)notifierViewTapped:(FDStatusBarNotifierView *)notifierView; // user tap the status bar message
+
+@end
@@ -0,0 +1,133 @@
+//
+// StatusBarNotifierView.m
+// StatusBarNotifier
+//
+// Created by Francesco Di Lorenzo on 05/09/12.
+// Copyright (c) 2012 Francesco Di Lorenzo. All rights reserved.
+//
+
+#import "FDStatusBarNotifierView.h"
+
+@interface FDStatusBarNotifierView ()
+
+@property (strong) UILabel *messageLabel;
+
+@end
+
+@implementation FDStatusBarNotifierView
+
+#define kNotifierViewInitialFramePortrait CGRectMake(0, 20, 320, 20)
+#define kNotifierViewFinalFramePortrait CGRectMake(0, 0, 320, 20)
+//#define kNotifierViewInitialFrameLandscape CGRectMake(0, 20, 480, 20)
+//#define kNotifierViewFinalFrameLandscape CGRectMake(0, 0, 480, 20)
+
+#define kMessageLabelInitialFramePortrait CGRectMake(10, 0, 300, 20)
+#define kMessageLabelInitialFrameLandscape CGRectMake(10, 0, 460, 20)
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ self.frame = kNotifierViewInitialFramePortrait;
+
+ self.messageLabel = [[UILabel alloc] initWithFrame:kMessageLabelInitialFramePortrait];
+ self.messageLabel.textColor = [UIColor whiteColor];
+ self.messageLabel.backgroundColor = [UIColor blackColor];
+ self.messageLabel.textAlignment = UITextAlignmentCenter;
+ self.messageLabel.font = [UIFont boldSystemFontOfSize:12];
+ [self addSubview:self.messageLabel];
+
+ self.timeOnScreen = 2.0;
+ }
+ return self;
+}
+
+- (id)initWithMessage:(NSString *)message {
+ self = [super init];
+ if (self) {
+ self.frame = kNotifierViewInitialFramePortrait;
+ self.message = message;
+ self.backgroundColor = [UIColor blackColor];
+
+ self.messageLabel = [[UILabel alloc] initWithFrame:kMessageLabelInitialFramePortrait];
+ self.messageLabel.textColor = [UIColor whiteColor];
+ self.messageLabel.text = message;
+ self.messageLabel.backgroundColor = [UIColor blackColor];
+ self.messageLabel.textAlignment = UITextAlignmentCenter;
+ self.messageLabel.font = [UIFont boldSystemFontOfSize:12];
+ [self addSubview:self.messageLabel];
+
+ self.timeOnScreen = 2.0;
+ }
+ return self;
+
+}
+
+- (id)initWithMessage:(NSString *)message delegate:(id /*<StatusBarNotifierViewDelegate>*/)delegate {
+ self = [super init];
+ if (self) {
+ self.frame = kNotifierViewInitialFramePortrait;
+ self.delegate = delegate;
+ self.message = message;
+ self.backgroundColor = [UIColor blackColor];
+
+ self.messageLabel = [[UILabel alloc] initWithFrame:kMessageLabelInitialFramePortrait];
+ self.messageLabel.textColor = [UIColor whiteColor];
+ self.messageLabel.text = message;
+ self.messageLabel.backgroundColor = [UIColor blackColor];
+ self.messageLabel.textAlignment = UITextAlignmentCenter;
+ self.messageLabel.font = [UIFont boldSystemFontOfSize:12];
+ [self addSubview:self.messageLabel];
+
+ self.timeOnScreen = 2.0;
+ }
+ return self;
+}
+
+- (void)showInWindow:(UIWindow *)window {
+ if (self.delegate && [self.delegate respondsToSelector:@selector(willPresentNotifierView:)])
+ [self.delegate willPresentNotifierView:self];
+
+ [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
+ [window insertSubview:self atIndex:0];
+
+ [UIView animateWithDuration:.4 animations:^{
+ self.frame = kNotifierViewFinalFramePortrait;
+ } completion:^(BOOL finished){
+
+ if (self.delegate && [self.delegate respondsToSelector:@selector(didPresentNotifierView:)])
+ [self.delegate didPresentNotifierView:self];
+
+ [NSTimer scheduledTimerWithTimeInterval:self.timeOnScreen target:self selector:@selector(hide) userInfo:nil repeats:NO];
+
+ }];
+}
+
+- (void)hide {
+
+ if (self.delegate && [self.delegate respondsToSelector:@selector(willHideNotifierView:)])
+ [self.delegate willHideNotifierView:self];
+
+ [UIView animateWithDuration:.4 animations:^{
+ self.frame = kNotifierViewInitialFramePortrait;
+ [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
+ } completion:^(BOOL finished){
+ if (finished) {
+
+ if (self.delegate && [self.delegate respondsToSelector:@selector(didHideNotifierView:)])
+ [self.delegate didHideNotifierView:self];
+
+ [self removeFromSuperview];
+ }
+ }];
+}
+
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
+ [self.delegate notifierViewTapped:self];
+}
+
+- (void)setMessage:(NSString *)message {
+ _message = message;
+ self.messageLabel.text = message;
+}
+
+@end
@@ -0,0 +1,49 @@
+**FDStatusBarNotifier** is a UIView subclass that let you display notifications using the space in which the status bar resides.
+
+It’s as easy to use as `UIAlertView`, here is an example:
+
+ // from a view controller
+ FDStatusBarNotifierView *notifierView = [[FDStatusBarNotifierView alloc] initWithMessage:@"Hi"];
+ notifierView.timeOnScreen = 3.0;
+ [notifierView showInWindow:self.view.window];
+
+
+When you call `showInWindow:` the status bar disappear and the notifier view takes its place with a smooth animation.
+
+![](http://github.com/frankdilo/FDStatusBarNotifierView/raw/master/Screenshot.png)
+
+# How to use it
+
+To use it just drag and drop `FDStatusBarNotifierView.h` and `FDStatusBarNotifierView.m` in your project, import the `.h` file in your view controller implementation and use the code shown in the example above.
+
+## Optional delegate methods
+
+I've also created some handy *self-explanatory* delegate methods, if you need them.
+
+ - (void)willPresentNotifierView:(FDStatusBarNotifierView *)notifierView; // before animation and showing view
+ - (void)didPresentNotifierView:(FDStatusBarNotifierView *)notifierView; // after animation
+ - (void)willHideNotifierView:(FDStatusBarNotifierView *)notifierView; // before hiding animation
+ - (void)didHideNotifierView:(FDStatusBarNotifierView *)notifierView; // after animation
+ - (void)notifierViewTapped:(FDStatusBarNotifierView *)notifierView; // user tap the status bar message
+
+# Contribute
+
+Feel free to help out by sending pull requests or by creating new issues.
+
+## TO DO
+
+- Add support for multiple orientations (currently only portrait is supported).
+- Add support for the iPad.
+- Option to dismiss the notifier view when the user tap it.
+
+# License
+
+## MIT License
+
+Copyright (c) 2012 Francesco Di Lorenzo
+
+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.
Submodule Sample Project added at 5b445f
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 91e6a4f

Please sign in to comment.