NotificationView
简介
您可以使用该库轻松实现 iOS 基本通知界面。提供了默认主题和暗色主题。您可以通过 UIImageView 仅使用图片将其附加到通知界面。您可以调整消失时间。您可以获得可见和消失状态的代理或回调。您可以获得点击的代理和回调。
主题 | 多种 |
---|---|
![]() |
![]() |
自定义 | 持续时间 |
---|---|
![]() |
![]() |
旋转 |
---|
![]() |
屏幕
- | iPhoneSE | iPhone8Plus |
---|---|---|
垂直 | ![]() |
![]() |
水平 | ![]() |
![]() |
- | iPhoneX | iPad |
---|---|---|
垂直 | ![]() |
![]() |
水平 | ![]() |
![]() |
主题
default | dark |
---|---|
![]() |
![]() |
类型
custom1 | custom2 |
---|---|
![]() |
![]() |
需求
NotificationView
使用 Swift 5.0 编写。兼容 iOS 8.0+
安装
版本说明
版本 0.2.1 引入 Swift 5.0 支持
版本 0.2.0 引入 Swift 4.2 支持
版本 0.1.1 引入 Swift 4.0 支持
CocoaPods
NotificationView 可通过 CocoaPods 获得。安装它,只需在 Podfile 中添加以下行
pod 'NotificationView'
Swift 包管理器
要将 NotificationView
通过 SPM 集成到 Xcode 11 项目中,请指定它在 Project > Swift Packages 中
https://github.com/pikachu987/NotificationView
使用
import NotificationView
默认通知
let notificationView = NotificationView.default
notificationView.title = title
notificationView.subtitle = subtitle
notificationView.body = body
notificationView.image = image
notificationView.show()
多个通知
let notificationView = NotificationView()
notificationView.title = title
notificationView.subtitle = subtitle
notificationView.body = body
notificationView.image = image
notificationView.show()
完成!
属性
通知视图
//Theme for NotificationView. There are dark mode and default mode and custom mode.
notificationView.theme
//The title of the NotificationView.
notificationView.title
//The subtitle of the NotificationView.
notificationView.subtitle
//The body of the NotificationView.
notificationView.body
//The image of the NotificationView.
notificationView.image
//The background color of the NotificationView.
notificationView.backgroundColor
//It is a dictionary that can contain any data.
notificationView.param
//The identifier for the NotificationView.
notificationView.identifier
//The time until the NotificationView is shown and then disappears.
notificationView.hideDuration
//An UIImageView that displays the AppIcon image.
notificationView.iconImageView
//An UILabel that displays the AppName text.
notificationView.appNameLabel
//An UILabel that displays the Date text.
notificationView.dateLabel
//An UILabel that displays the Title text.
notificationView.titleLabel
//An UILabel that displays the Subtitle text.
notificationView.subtitleLabel
//An UILabel that displays the Body text.
notificationView.bodyLabel
//An UIImageView that displays the Image.
notificationView.imageView
方法
通知视图 显示
notificationView.show()
notificationView.show { (state) in
print("callback: \(state)")
}
notificationView.showAfter(0.1)
notificationView.showAfter(0.1) { (state) in
print("callback: \(state)")
}
通知视图 隐藏
notificationView.hide()
notificationView.hideAfter(0.1)
委托
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let notificationView = NotificationView()
notificationView.delegate = self
}
}
extension ViewController: NotificationViewDelegate {
/**
Called when NotificationView is willAppear.
- Parameters:
- notificationView: NotificationView
*/
func notificationViewWillAppear(_ notificationView: NotificationView) {
print("delegate: notificationViewWillAppear")
}
/**
Called when NotificationView is didAppear.
- Parameters:
- notificationView: NotificationView
*/
func notificationViewDidAppear(_ notificationView: NotificationView) {
print("delegate: notificationViewDidAppear")
}
/**
Called when NotificationView is willDisappear.
- Parameters:
- notificationView: NotificationView
*/
func notificationViewWillDisappear(_ notificationView: NotificationView) {
print("delegate: notificationViewWillDisappear")
}
/**
Called when NotificationView is didDisappear.
- Parameters:
- notificationView: NotificationView
*/
func notificationViewDidDisappear(_ notificationView: NotificationView) {
print("delegate: notificationViewDidDisappear")
}
/**
Called when the NotificationView is touched.
- Parameters:
- notificationView: NotificationView
*/
func notificationViewDidTap(_ notificationView: NotificationView) {
print("delegate: notificationViewDidTap")
}
}
自定义
let notificationView = NotificationView()
notificationView.title = title
notificationView.subtitle = subtitle
notificationView.body = body
notificationView.image = image
notificationView.theme = .custom
notificationView.backgroundColor = .red
notificationView.appNameLabel.textColor = .blue
notificationView.dateLabel.textColor = .blue
notificationView.titleLabel.textColor = .blue
notificationView.subtitleLabel.textColor = .blue
notificationView.bodyLabel.textColor = .blue
notificationView.show()
作者
Pikachu987, [email protected]
许可协议
NotificationView 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。