TestsTested | β |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2017 |
SwiftSwift Version | 3.1 |
SPMSupports SPM | β |
Maintained by gokul.
FYI: Updated with XCode 9.0 & swift 4.0.
GLNotificationBar
is a library that allows you to easily create banner notifications that appear on top of screen, used to handle push notification in active state.Made with xcode 8.3.1
and swift 3
To run the example project, clone the repo, and run pod install
from the Example directory first.
GLNotificationBar
requires iOS 8.0+.
GLNotificationBar is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'GLNotificationBar'
Copy the file GLNotificationBar.swift
& GLNotificationBar.xib
from ~/GLNotificationBar/GLNotificationBar/Classes to your project.
let notificationBar = GLNotificationBar(title: "Today Quote", message: "Yesterday is today's memory, and tomorrow is today's dream.", preferredStyle: .DetailedBanner, handler: nil)
notificationBar.addAction(GLNotifyAction(title: "Like", style: .Default, handler: { (action) in
print("I Like this quote")
}))
notificationBar.addAction(GLNotifyAction(title: "Cancel", style: .Cancel, handler: nil))
pod 'GLNotificationBar'
@import GLNotificationBar;
at top of your viewcontroller class.GLNotificationBar * notificationBar = [[GLNotificationBar alloc]initWithTitle:@"Today Quote" message:@"Yesterday is today's memory, and tomorrow is today's dream." preferredStyle:0 handler:nil];
[notificationBar addAction:[[GLNotifyAction alloc]initWithTitle:@"Like" style:0 handler:^(GLNotifyAction * action) {
NSLog(@"I Like this quote");
//NSLog(@"Text reply %@",action.textResponse);
}]];
[notificationBar addAction:[[GLNotifyAction alloc]initWithTitle:@"Cancel" style:4 handler:nil]];
GLNotificationBar
is simple to use,implementation is similar to UIAlertController
.
let notificationBar = GLNotificationBar(title: "hallowean", message: "πHi there! We've missed you. Enjoy the new hallowean sticker,borders,bgs on your app.ππ
π»", preferredStyle: .DetailedBanner, handler: nil)
This simply presents GLNotificationBar with given title and message,handler can be used to catch tap gesture on notification bar. The default behavior of notification bar is, dismissed automatically when tapped on it.
There are two types of GLNotificationBar
style and Five type of GLNotifyAction
types.
.DetailedBanner
.DetailedBanner style is similar to ios10 style notification bar, swiping down this type of notification open's in detail, which may include GLNotifyAction's
GLNotifyAction
can be added to GLNotificationBar
as follows
let cancelButton = GLNotifyAction(title: "Cancel", style: .Cancel) { (result) in
print(result.actionTitle)
}
notificationBar.addAction(cancelButton)
OR
notificationBar.addAction(GLNotifyAction(title: "Cancel", style: .Cancel) { (result) in
print(result.actionTitle)
})
GLNotifyAction also has four different types each performs their respective action.
public enum GLNotificationActionType {
case Default // Apply the default style to the actionβs button.
case Destructive //Apply a style that indicates the action might change or delete data.
case TextInput //Apply a style that indicates the action opens an textinput field helps to respond notification as string.
case OnlyTextInput //Apply a style which removes all other action added and simply adds text field as input to respond notification.
case Cancel //Apply a style that indicates the action cancels the operation and leaves things unchanged.
}
.SimpleBanner
GLNotifyAction
added to this type of notification bar will not be taken into account.GLNotifyAction
's .OnlyTextInput
notificationBar.addAction(GLNotifyAction(title: "Reply", style: .OnlyTextInput) { (result) in
print(result.textResponse)
})
notificationBar.showTime
notificationBar.showTime(3.0)
notificationBar.notificationSound
notificationBar.notificationSound("Your sound name", ofType: ".mp3", vibrate: true)
GLNotificationBar
does't play any sound, to play notification sound add this method.gokul, [email protected]
GLNotificationBar is available under the MIT license. See the LICENSE file for more info.