测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布时间最后发布 | 2016年10月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Sai Prasanna 维护。
这是从 TSMessages 库移植到 Swift 的版本。已删除 iOS6 设计选项。
这个库提供了一个简单的类,可以在屏幕顶部显示小通知视图。
通知从屏幕顶部移动到导航条下方并停留几秒钟,具体时间取决于显示文本的长度。要在时间用完前关闭通知,用户可以将其向上滑动或轻轻点击。
已经为您设置了四种不同的类型:成功、错误、警告、消息(请查看截图)
请查看示例项目以了解如何使用此库。
v0.2.0 -> Swift 2.2
v0.3.0 -> Swift 3.0
将 SWMessages 目录中的源文件和资源文件复制到您的项目中。这是在 iOS 7 中使其工作的唯一方法。
iOS7+
要显示通知,请使用以下代码
SWMessage.sharedInstance.showNotificationWithTitle(
"Title",
subtitle: "Subtitle",
type: .success
)
// Add a button inside the message
SWMessage.sharedInstance.showNotificationInViewController (
self,
title: "Update available",
subtitle: "Please update our app. We added AI to replace you",
image: nil,
type: .success,
duration: .automatic,
callback: nil,
buttonTitle: "Update",
buttonCallback: {
SWMessage.showNotificationWithTitle("Thanks for updating", type: .success)
},
atPosition: .top,
canBeDismissedByUser: true
)
You can define a default view controller in which the notifications should be displayed:
```swift
SWMessage.sharedInstance.defaultViewController = myNavController
您可以为消息设置自定义的偏移量。
SWMessage.sharedInstance.offsetHeightForMessage = 10.0
您可以在显示之前自定义消息视图,例如设置透明度值,或添加自定义子视图。
SWMessage.customizeMessageView = { (messageView) in
messageView.alpha = ..
messageView.addSubView(someView)
}
您可以通过设置 styleForMessageType 回调来自定义消息视图的默认类型,它接受消息类型作为参数并返回 SWMessageView.Style 结构对象。
SWMessageView.styleForMessageType = { (type)
....
return SWMessageView.Style(...)
}
创建新通知时可以设置以下属性
除了标题和通知类型外,列出的所有值都是可选的
如果您不希望有详细说明(标题下的文本),则无需设置。通知将自动正确调整大小。
SWMessages符合MIT许可。有关更多信息,请参阅LICENSE文件。