Toast-Swift Documentation

repository·master·Indexed 26 days ago

https://github.com/scalessec/toast-swift

A lightweight Swift extension that adds toast notifications to UIView objects. This native Swift port of the original Toast for iOS library allows for customizable durations, positions, titles, and images, with support for custom ToastStyle objects and global configuration via ToastManager.shared.

Tokens
860
Snippets
2
Records
4
Agent score
37%

What's inside Toast-Swift

  1. Display basic toast notifications

    master

    Toast-Swift extends UIView to allow triggering notifications with simple method calls. You can specify duration, position, titles, images, and tap completion handlers.

    // 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()
  2. Customize toast appearance and behavior

    master

    You can create custom ToastStyle objects for specific toasts or configure the global ToastManager.shared to apply settings to all subsequent toasts.

    // create a new style
    var style = ToastStyle()
    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)
    
    // set the shared style for all toasts going forward
    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
  3. Check Toast-Swift compatibility

    master

    Ensure your environment meets the requirements for the version you are using:

    • Version 5.x.x: Swift 5 and Xcode 10.2 or later.
    • Version 4.x.x: Swift 4.2 and Xcode 10.
    • Version 3.x.x: Swift 4 and Xcode 9.
    • Version 2.x.x: Swift 3 and Xcode 8.
    • Version 1.4.x: Swift 2.2 and Xcode 7.3.
    • Version 1.0.0: Swift 2.1 and earlier.