Cezary Wojcik 513ca17ffe Merge pull request #82 from kshdeo/swift
Swift Style selectors + Option to change Font size
2016-04-06 23:11:46 -07:00
2015-08-27 11:48:35 -07:00
2016-04-07 11:36:52 +05:30
2015-07-12 19:16:21 -07:00
2013-09-19 01:57:31 -07:00
2014-03-15 15:21:37 -07:00
2014-06-08 14:23:33 -07:00
2015-08-27 11:48:35 -07:00

CWStatusBarNotification - Swift Branch

Build Status

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

demo

Requirements

CWStatusBarNotification uses Swift 2.0 and requires iOS 7.0+.

Works for iPhone and iPad.

Installation

Copy Files

Copy the two *.swift files from CWStatusBarNotification/CWStatusBarNotification/ into your project.

Usage

You need to create a CWStatusBarNotification object. It is recommended that you do so by attaching it as a property to a view controller.

let notification = CWStatusBarNotification()

After you have a CWStatusBarNotification object, you can simply call the displayNotificationMessage(message: String, duration: NSTimeInterval) method:

self.notification.displayNotificationWithMessage("Hello, World!", duration: 1.0)

If you prefer to manually choose when to display and dismiss the notification, you can do so as well:

self.notification.displayNotificationWithMessage("Hello", completion: nil)
// wait until you need to dismiss
self.notification.dismissNotification()

Behavior on Tap

The default behavior when the notification is tapped is to dismiss it. However, you can override this behavior by setting the notificationTappedClosure closure to something different.

For example:

self.notification.notificationTappedClosure = {
    println("notification tapped")
    // more code here
}

Note that overriding this closure means that the notification will no longer be dismissed when tapped. If you want the notification to still dismiss when tapped, make sure to implement the following when overriding the closure:

self.notification.notificationTappedClosure = {
    if !self.notificationIsDismissing {
        self.dismissNotification()
    }
    // more code here
}

Customizing Appearance

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

Example:

self.notification.notificationLabelBackgroundColor = UIColor.blackColor()
self.notification.notificationLabelTextColor = UIColor.greenColor()

custom colors

The default value of notificationLabelBackgroundColor is UIColor.blackColor().

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 CWNotificationStyle.StatusBarNotification or CWNotificationStyle.NavigationBarNotification.

Example:

self.notification.notificationStyle = .NavigationBarNotification

custom style

The default value of notificationStyle is CWNotificationStyle.StatusBarNotification.

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:

  • CWNotificationAnimationStyle.Top
  • CWNotificationAnimationStyle.Bottom
  • CWNotificationAnimationStyle.Left
  • CWNotificationAnimationStyle.Right

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

The default value for notificationAnimationInStyle is CWNotificationAnimationStyle.Bottom.

The default value for notificationAnimationOutStyle is CWNotificationAnimationStyle.Bottom.

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) 2015 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.
S
Description
A library that allows you to easily create text-based notifications that appear on the status bar.
Readme MIT 6.8 MiB
Languages
Objective-C 98%
Ruby 2%