Skip to content

Instantly share code, notes, and snippets.

@cruffenach
Last active December 30, 2015 02:39
Show Gist options
  • Save cruffenach/7763917 to your computer and use it in GitHub Desktop.
Save cruffenach/7763917 to your computer and use it in GitHub Desktop.

CWStatusBarNotification

CWStatusBarNotification is a library that allows you to easily create notifications that appear on the status bar.

demo

Requirements

CWStatusBarNotification uses ARC and requires iOS 7.0+.

Works for iPhone and iPad.

Installation

CocoaPods

pod 'CWStatusBarNotification', '~> 3.0'

Manual

Copy the folder CWStatusBarNotification to your project.

Usage

Notifications can be created through CWStatusBarNotificationManager's showNotificationWithOptions:completionBlock: This will queue up a notification with the options specified. You provide options for your notification in a dictionary using the keys in CWStatusBarNotification.h

Example

This code

NSDictionary *options = @{kCWStatusBarNotificationTextKey : @"Hello World!",
                          kCWStatusBarNotificationTextAlignmentKey : @(NSTextAlignmentCenter),
                          kCWStatusBarNotificationBackgroundColorKey : [UIColor redColor],
                          kCWStatusBarNotificationAnimationTypeKey : @(CWStatusBarNotificationAnimationTypeSpring),
                          kCWStatusBarNotificationNotificationInAnimationStyleKey : @(CWStatusBarNotificationAnimationStyleLeft),
                          kCWStatusBarNotificationNotificationOutAnimationStyleKey : @(CWStatusBarNotificationAnimationStyleRight),
                          kCWStatusBarNotificationAnimateInTimeIntervalKey : @(0.5),
                          kCWStatusBarNotificationAnimateOutTimeIntervalKey: @(0.5)};
[CWStatusBarNotificationManager showNotificationWithOptions:options
                                            completionBlock:^{
                                                NSLog(@"Completed");                                            
                                            }];

Generates this

Customizing Appearance

First of all, you can customize the background color and text color using the following properties: notificationLabelBackgroundColor and notificationLabelTextColor.

Example:

notification.notificationLabelBackgroundColor = [UIColor blackColor];
notification.notificationLabelTextColor = [UIColor greenColor];

custom colors

The default value of notificationLabelBackgroundColor is [[UIApplication sharedApplication] delegate].window.tintColor.

The default value of notification.notificationLabelTextColor is [UIColor whiteColor].

Finally, you can also choose from two styles - a notification the size of the status bar, or a notification the size of the status bar and a navigation bar. Simply change the notificationStyle property of the CWStatusBarNotification object to either CWNotificationStyleStatusBarNotification or CWNotificationStyleNavigationBarNotification.

custom style

The default value of notificationStyle is CWNotificationStyleStatusBarNotification.

Customizing Animation

There are two properties that determine the animation style of the notification: notificationAnimationInStyle and notificationAnimationOutStyle. Each can take on one of four values:

  • CWNotificationAnimationStyleTop
  • CWNotificationAnimationStyleBottom
  • CWNotificationAnimationStyleLeft
  • CWNotificationAnimationStyleRight

The notificationAnimationInStyle describes where the notification comes from, whereas the notificationAnimationOutStyle describes where the notification will go.

The default value for notificationAnimationInStyle is CWNotificationAnimationStyleTop.

The default value for notificationAnimationOutStyle is CWNotificationAnimationStyleTop.

Additional Remarks

The notifications will work in both screen orientations, however, screen rotation while a notification is displayed is not yet fully supported.

License

The MIT License (MIT)

Copyright (c) 2013 Cezary Wojcik <http://www.cezarywojcik.com>

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment