Skip to content

zjinhu/Toast_SwiftUI

Repository files navigation

Toast_SwiftUI

SPM Xcode 14.0+ iOS 14.0+ Swift 5.0+ SwiftUI 3.0+

Example

Toast_SwiftUI has a built-in plain text toast, which can be used only by toast.showText

toast.showText("Toast at bottom")

You can also customize your own Toast style, no intrusion, no inheritance, completely native, just need to expand the method of the controller, [see CustomView for details](https://github.com/jackiehu/Toast_SwiftUI/blob /main/Example/Toast_SwiftUI/CustomView.swift)

extension ToastManager {
    //展示自定义View//自己可以重写替换
   func showCustom(){
        show {
            CustomView()
        }
    }
}

Usage

Create a controller on the page that needs to pop up Toast

    @EnvironmentObject private var toast: ToastManager
    //OR
    @StateObject var toast = ToastManager()

Add a controller to the page

.addToast(toast)

Control the position where Toast pops up, and then call the show method

toast.position = .bottom
toast.showText("Toast at bottom")

controller

    ///Toast停留时长
    public var duration: TimeInterval = 3
    ///Toast显示位置
    public var position: ToastPosition = .bottom
    ///Toast距离屏幕边缘
    public var padding: CGFloat = 10

Install

cocoapods

  1. Add pod 'Toast_SwiftUI' in Podfile

  2. Execute pod install or pod update

  3. Import import Toast_SwiftUI

Swift Package Manager

Starting from Xcode 11, the Swift Package Manager is integrated, which is very convenient to use. Toast_SwiftUI also supports integration via Swift Package Manager.

Select File > Swift Packages > Add Pacakage Dependency in Xcode's menu bar, and enter in the search bar

https://github.com/jackiehu/Toast_SwiftUI, you can complete the integration

Manual Install

Toast_SwiftUI also supports manual Install, just drag the Toast_SwiftUI folder in the Sources folder into the project that needs to be installed

Author

jackiehu, 814030966@qq.com

More brick tools to speed up APP development

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

license

Toast_SwiftUI is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published