Toast-Swift

CocoaPods Version Carthage Compatible

Toast-Swift 是一个 Swift 扩展,它向 UIView 对象类添加了 toast 通知。它的目的是简单、轻量级且易于使用。大多数 toast 通知可以通过单行代码触发。

Toast-Swift 是 iOS 版 Toast 的原生 Swift 移植版本。

屏幕截图

Toast-Swift Screenshots

基本示例

// 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.1.1'

并在您的代码中添加 import Toast_Swift

Carthage

要使用 Carthage 将 Toast-Swift 集成到您的 Xcode 项目中,请在您的 Cartfile 中指定它

github "scalessec/Toast-Swift" ~> 5.1.1

运行 carthage update 以构建框架,并将构建的 ToastSwiftFramework.framework 拖到您的 Xcode 项目中。

并在您的代码中添加 import ToastSwiftFramework

Swift Package Manager

当使用 Xcode 11 或更高版本时,您可以通过转到您的项目设置 > Swift Packages 并通过提供 GitHub URL 来添加存储库来安装 Toast。或者,您可以转到 File > Swift Packages > Add Package Dependencies...

手动

  1. Toast.swift 添加到您的项目。
  2. 给自己来一杯冰镇 🍺 吧。

兼容性

隐私

Toast-Swift 不会收集任何数据。库中提供了一个隐私清单。有关详细信息,请参阅 Apple 的文档

MIT 许可证

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.