Toast-Swift 是一个 Swift 扩展,它向 UIView
对象类添加了 toast 通知。它的目的是简单、轻量级且易于使用。大多数 toast 通知可以通过单行代码触发。
Toast-Swift 是 iOS 版 Toast 的原生 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 将 Toast-Swift 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
pod 'Toast-Swift', '~> 5.1.1'
并在您的代码中添加 import Toast_Swift
。
要使用 Carthage 将 Toast-Swift 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "scalessec/Toast-Swift" ~> 5.1.1
运行 carthage update
以构建框架,并将构建的 ToastSwiftFramework.framework
拖到您的 Xcode 项目中。
并在您的代码中添加 import ToastSwiftFramework
。
当使用 Xcode 11 或更高版本时,您可以通过转到您的项目设置 > Swift Packages
并通过提供 GitHub URL 来添加存储库来安装 Toast
。或者,您可以转到 File
> Swift Packages
> Add Package Dependencies...
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 一起使用。Toast-Swift 不会收集任何数据。库中提供了一个隐私清单。有关详细信息,请参阅 Apple 的文档。
Copyright (c) 2015-2024 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.