Toast-Swift
Toast-Swift 是一个 Swift 扩展,它向 UIView
对象类添加 toast 通知功能。它的设计理念是简单、轻量级且易于使用。大多数 toast 通知都可以通过一行代码触发。
Toast-Swift 是 Toast for iOS 的 Swift 原生版本。
屏幕截图
基本示例
// basic usage
self.view.makeToast("This is a piece of toast")
// toast with a specific duration and position
self.view.makeToast("This is a piece of toast", duration: 3.0, position: .top)
// toast presented with multiple options and with a completion closure
self.view.makeToast("This is a piece of toast", duration: 2.0, point: CGPoint(x: 110.0, y: 110.0), title: "Toast Title", image: UIImage(named: "toast.png")) { didTap in
if didTap {
print("completion from tap")
} else {
print("completion without tap")
}
}
// display toast with an activity spinner
self.view.makeToastActivity(.center)
// display any view as toast
self.view.showToast(myView)
// immediately hides all toast views in self.view
self.view.hideAllToasts()
但是等等,还有更多!
// create a new style
var style = ToastStyle()
// this is just one of many style options
style.messageColor = .blue
// present the toast with the new style
self.view.makeToast("This is a piece of toast", duration: 3.0, position: .bottom, style: style)
// or perhaps you want to use this style for all toasts going forward?
// just set the shared style and there's no need to provide the style again
ToastManager.shared.style = style
self.view.makeToast("This is a piece of toast") // now uses the shared style
// toggle "tap to dismiss" functionality
ToastManager.shared.isTapToDismissEnabled = true
// toggle queueing behavior
ToastManager.shared.isQueueEnabled = true
请查看演示项目以获取更多示例。
设置说明
CocoaPods
要使用 CocoaPods 将 Toast-Swift 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它。
pod 'Toast-Swift', '~> 5.0.0'
并在您的代码中添加 import Toast_Swift
。
Carthage
要使用 Carthage 将 Toast-Swift 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它。
github "scalessec/Toast-Swift" ~> 5.0.0
运行 carthage update
以构建框架,并将其构建的 ToastSwiftFramework.framework
拖入您的 Xcode 项目。
并在您的代码中添加 import ToastSwiftFramework
。
手动
- 将
Toast.swift
添加到您的项目。 - 给自己来一杯冰的
🍺 .
兼容性
- 版本
5.x.x
需要 Swift 5 和 Xcode 10.2。 - 版本
4.x.x
需要 Swift 4.2 和 Xcode 10。 - 版本
3.x.x
需要 Swift 4 和 Xcode 9。 - 版本
2.x.x
需要 Swift 3 和 Xcode 8。 - 版本
1.4.x
需要 Swift 2.2 和 Xcode 7.3。 - 版本
1.0.0
可以与 Swift 2.1 及更早版本的 Xcode 一起使用。
MIT 许可证
Copyright (c) 2015-2019 Charles Scalesse.
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.