测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年11月 |
SwiftSwift 版本 | 3.1 |
SPM支持 SPM | ✗ |
由 gokul 维护。
注意:更新了 Xcode 9.0 & swift 4.0.
GLNotificationBar
是一个库,允许您轻易地创建出现在屏幕顶部的横幅通知,用于在活动状态下处理推送通知。用 xcode 8.3.1
和 swift 3
构建。
要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
。
GLNotificationBar
需要 iOS 8.0+。
GLNotificationBar 可通过 CocoaPods 获取。要安装它,只需将以下行添加到 Podfile
即可
pod 'GLNotificationBar'
将文件 GLNotificationBar.swift
& GLNotificationBar.xib
从 ~/GLNotificationBar/GLNotificationBar/Classes 复制到您的项目中。
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;
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
使用简单,实现方式类似于 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)
这简单地展示了带有指定标题和消息的 GLNotificationBar,handler 可用来捕获通知条上的点击手势。通知条的默认行为是,点击时会自动消失。
存在两种类型的 GLNotificationBar
风格和五种类型的 GLNotifyAction
。
详细横幅
.DetailedBanner 风格类似于 os10 风格的通知栏,向下滑动此类型的通知会在详情中打开,可能包括 GLNotifyAction's
可以将 GLNotifyAction
添加到如下 GLNotificationBar
let cancelButton = GLNotifyAction(title: "Cancel", style: .Cancel) { (result) in
print(result.actionTitle)
}
notificationBar.addAction(cancelButton)
或者
notificationBar.addAction(GLNotifyAction(title: "Cancel", style: .Cancel) { (result) in
print(result.actionTitle)
})
GLNotifyAction 同样有四种不同类型,每种类型都执行相应的操作。
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.
}
简单横幅
GLNotifyAction
将不会得到考虑。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
不会播放任何声音,要播放通知声音,请添加此方法。gokul,[email protected]
GLNotificationBar在MIT许可下可用。有关更多信息,请参阅LICENSE文件。