A Swift Toast view - iOS 14 style and newer - built with UIKit. 🍞

Overview

Toast-Swift

Codacy Badge

A Swift Toast view - iOS 14 style - built with UIKit. 🍞

Installation

Swift Package Manager

You can use The Swift Package Manager to install Toast-Swift by adding the description to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/BastiaanJansen/Toast-Swift", from: "1.0.3")
]

CocoaPods

pod "ToastViewSwift"

Usage

To create a simple text based toast:

let toast = Toast.text("Safari pasted from Notes")
toast.show()

Or add a subtitle:

let toast = Toast.text("Safari pasted from Notes", subtitle: "A few seconds ago")
toast.show()

If you want to add an icon, use the default method to construct a toast:

let toast = Toast.default(
    image: UIImage(systemname: "airpodspro")!,
    title: "Airpods Pro",
    subtitle: "Connected"
)
toast.show()

Want to use a different layout, but still use the Apple style? Create your own view and inject it into the AppleToastView class when creating a custom toast:

let customView: UIView = // Custom view

let appleToastView = AppleToastView(child: customView)

let toast = Toast.custom(view: appleToastView)
toast.show()

The show method accepts several optional parameters. haptic of type UINotificationFeedbackGenerator.FeedbackType to use haptics and after of type TimeInterval to show the toast after a certain amount of time:

toast.show(haptic: .success, after: 1)

Configuration options

The text, default and custom methods support custom configuration options. The following options are available:

Name Description Type Default
autoHide When set to true, the toast will automatically close itself after display time has elapsed. Bool true
displayTime The duration the toast will be displayed before it will close when autoHide set to true. TimeInterval 4
animationTime Duration of the show and close animation. TimeInterval 0.2
attachTo The view which the toast view will be attached to. UIView nil
let config = ToastConfiguration(
    autoHide: true,
    displayTime: 5,
    animationTime: 0.2
)

let toast = toast.text("Safari pasted from Notes", config: config)

Custom toast view

Don't like the default Apple'ish style? No problem, it is also possible to use a custom toast view with the custom method. Firstly, create a class that confirms to the ToastView protocol:

class CustomToastView : UIView, ToastView {
    private let text: String

    public init(text: String) {
        self.text = text
    }

    func createView(for toast: Toast) {
        // View is added to superview, create and style layout and add constraints
    }
}

Use your custom view with the custom construct method on Toast:

let customToastView: ToastView = CustomToastView(text: "Safari pasted from Notes")

let toast = Toast.custom(view: customToastView)
toast.show()

Licence

Toast-Swift is available under the MIT licence. See the LICENCE for more info.

Stargazers repo roster for @BastiaanJansen/Toast-Swift

Comments
  • Tap to dismiss

    Tap to dismiss

    Hello - Thanks for this, really like it.

    A little feature request. Please could you implement an option in the config for a 'tap to dismiss' option?

    Cheers :)

    opened by drivediary 5
  • Support animation type

    Support animation type

    Thinking of making a PR that will give the ability to choose the toast entering/exiting animation.

    let config = ToastConfiguration(
        direction: .up,
        autoHide: true,
        enablePanToClose: true,
        displayTime: 5,
        animationTime: 0.2
    +   animationType: .slide 
    )
    

    also fade animation type can be an option.

    What do you think 🤔

    enhancement 
    opened by Nikoloutsos 2
  • Update AppleToastView.swift

    Update AppleToastView.swift

    On iOS 15.4 the toast doesn't show perfect rounded, printing frame.height on style() seems to be less than 58 that is minHeight. Calling style async during create toast fixes the problem.

    Simulator Screen Shot - iPhone 13 - 2022-05-06 at 08 37 52

    bug 
    opened by honcon 2
  • Add support for iOS 12.

    Add support for iOS 12.

    I want to use this library in an app that still needs to support iOS 12. Apart from the default imageTint being UIColor.label, it works perfectly fine on iOS 12.

    opened by Zandor300 2
  • Need toast message position ?

    Need toast message position ?

    /* Its not a issue its suggestion */ –> it would be great if ya provide where to show toast like top, bottom, center ..... –> toast need a dynamic height like what if your title and subtile have more then 3 lines ?

    thank you... its suggestion not a complain 🙂

    enhancement 
    opened by santespatel 2
  • Add ability to choose entering/exiting animations and fix on pan gesture

    Add ability to choose entering/exiting animations and fix on pan gesture

    Hi there @BastiaanJansen 👋 , I found some time and as promised in #24 this PR will give the ability to select your preferred animations. I've added a .custom type where user can give his own AffineAnimation. I took it one step further and give the ability to user to select different entering/exiting animations.

    Also I fixed an issue I found where panGesture did not work when toast direction is .bottom. Last but not least I changed the pan gesture threshold to 15.

    Have a nice weekend 😄

    opened by Nikoloutsos 1
  • Custom toast view

    Custom toast view

    On your code page you have an example for CustomToastView, could you add some sample code of what would go into the func createView(for toast: Toast).

    opened by Maverick1000 1
  • Add support for attributed strings

    Add support for attributed strings

    As requested here. AttributedStrings are now supported for both icon and text toasts.

    Now we can use custom fonts (and everything else NSAttributedString supports)

    opened by Nikoloutsos 0
  • Running resolver because the following dependencies were added: 'toast-swift'

    Running resolver because the following dependencies were added: 'toast-swift'

    Hello, I have a problem with compiling:

    a resolved file is required when automatic dependency resolution is disabled and should be placed at /Volumes/workspace/repository/UOnLoad.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved. Running resolver because the following dependencies were added: 'toast-swift' (https://github.com/BastiaanJansen/toast-swift)2022-12-09 11:43:56.738 xcodebuild[4147:18228] Writing error result bundle to /var/folders/r0/yrl1s4f524n1lpryy_y16t2r0000gn/T/ResultBundle_2022-09-12_11-43-0056.xcresult

    opened by Dozorov 0
  • Add support for toast Direction

    Add support for toast Direction

    This PR adds support for toast Direction. Now it is able to show toast at bottom as requested here https://github.com/BastiaanJansen/toast-swift/issues/4

    opened by Nikoloutsos 0
  • Add delegate for show and close callbacks.

    Add delegate for show and close callbacks.

    Adds a ToastDelegate per requested in https://github.com/BastiaanJansen/toast-swift/issues/16

    Usage

    let toast = Toast.text("Safari pasted from Notes", subtitle: "A few seconds ago")
    toast.delegate = self
    toast.show()
    

    Below delegate functions are optional to implement when implementing ToastDelegate.

    extension MyViewController: ToastDelegate {
    
        func willShowToast(_ toast: Toast) {
            print("Toast will be shown after this")
        }
    
        func didShowToast(_ toast: Toast) {
            print("Toast was shown")
        }
    
        func willCloseToast(_ toast: Toast) {
            print("Toast will be closed after this")
        }
    
        func didCloseToast(_ toast: Toast) {
            print("Toast was closed (either automatically, dismissed by user or programmatically)")
        }
    
    }
    

    Fixes https://github.com/BastiaanJansen/toast-swift/issues/16

    opened by Zandor300 0
  • Timer invalidation breaking pan gesture

    Timer invalidation breaking pan gesture

    With the current version the closeTimer?.invalidate() in the pan gesture handler is breaking the gesture with the following error: [SystemGestureGate] <0x143508050> Gesture: System gesture gate timed out.. The gesture handler is then not called anymore and the toast is then frozen and is not disappearing anymore. Does someone else has a similar behavior? It tested it on Xcode 14.0.1, 14.1 - iOS 16 Simulator and device with SwiftUI and UIKit in a plain project.

    If I remove the invalidation everything works well, but I cannot figure out why this happens.

    bug 
    opened by julianpomper 4
  • Attach to view

    Attach to view

    I got problems attaching the toast to the top of the tabBar without attach argument it show in the top of the view controller, I want it to show to the bottom of it when trying utilsUi.showToast(title: "tet", message: "test", attachTo: self.tabBarController?.tabBar) I got crash

    bug help wanted 
    opened by Dave181295 4
Releases(1.3.0)
  • 1.3.0(Jan 7, 2023)

    What's Changed

    • Add ability to choose entering/exiting animations and fix on pan gesture by @Nikoloutsos in https://github.com/BastiaanJansen/toast-swift/pull/25

    Full Changelog: https://github.com/BastiaanJansen/toast-swift/compare/1.2.0...1.3.0

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Dec 30, 2022)

    What's Changed

    • Add support for attributed strings by @Nikoloutsos in https://github.com/BastiaanJansen/toast-swift/pull/23

    Full Changelog: https://github.com/BastiaanJansen/toast-swift/compare/1.1.3...1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.3(Dec 8, 2022)

    What's Changed

    • fix typo: capital letter by @nmtitov in https://github.com/BastiaanJansen/toast-swift/pull/20
    • Add support for toast Direction by @Nikoloutsos in https://github.com/BastiaanJansen/toast-swift/pull/21

    New Contributors

    • @nmtitov made their first contribution in https://github.com/BastiaanJansen/toast-swift/pull/20
    • @Nikoloutsos made their first contribution in https://github.com/BastiaanJansen/toast-swift/pull/21

    Full Changelog: https://github.com/BastiaanJansen/toast-swift/compare/1.1.2...1.1.3

    Source code(tar.gz)
    Source code(zip)
  • 1.1.2(Nov 2, 2022)

    What's Changed

    • Add delegate for show and close callbacks. by @Zandor300 in https://github.com/BastiaanJansen/toast-swift/pull/17

    Full Changelog: https://github.com/BastiaanJansen/toast-swift/compare/1.1.1...1.1.2

    Source code(tar.gz)
    Source code(zip)
  • 1.1.1(Oct 15, 2022)

    What's Changed

    • Resolve issue or retain cycle by @lukszar in https://github.com/BastiaanJansen/toast-swift/pull/15

    New Contributors

    • @lukszar made their first contribution in https://github.com/BastiaanJansen/toast-swift/pull/15

    Full Changelog: https://github.com/BastiaanJansen/toast-swift/compare/1.1.0...1.1.1

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Jul 28, 2022)

    What's Changed

    • Adding TapToClose and PanToClose feature by @allen870619 in https://github.com/BastiaanJansen/toast-swift/pull/13

    New Contributors

    • @allen870619 made their first contribution in https://github.com/BastiaanJansen/toast-swift/pull/13

    Full Changelog: https://github.com/BastiaanJansen/toast-swift/compare/1.0.6...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.6(May 6, 2022)

    What's Changed

    • Update AppleToastView.swift by @honcon in https://github.com/BastiaanJansen/toast-swift/pull/9

    New Contributors

    • @honcon made their first contribution in https://github.com/BastiaanJansen/toast-swift/pull/9

    Full Changelog: https://github.com/BastiaanJansen/toast-swift/compare/1.0.5...1.0.6

    Source code(tar.gz)
    Source code(zip)
  • 1.0.5(Feb 9, 2022)

    What's Changed

    • Add support for iOS 11 by @giobass in https://github.com/BastiaanJansen/toast-swift/pull/8

    New Contributors

    • @giobass made their first contribution in https://github.com/BastiaanJansen/toast-swift/pull/8

    Full Changelog: https://github.com/BastiaanJansen/toast-swift/compare/1.0.4...1.0.5

    Source code(tar.gz)
    Source code(zip)
  • 1.0.4(Nov 9, 2021)

    What's Changed

    • Add support for iOS 12. by @Zandor300 in https://github.com/BastiaanJansen/Toast-Swift/pull/6
    • Update background color when switching between light and dark mode. by @Zandor300 in https://github.com/BastiaanJansen/Toast-Swift/pull/5

    New Contributors

    • @Zandor300 made their first contribution in https://github.com/BastiaanJansen/Toast-Swift/pull/6

    Full Changelog: https://github.com/BastiaanJansen/Toast-Swift/compare/1.0.3...1.0.4

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jun 30, 2021)

Owner
Bastiaan Jansen
Software Engineering student at University of Applied Sciences Leiden in The Netherlands.
Bastiaan Jansen
Bulletin / 'Toast' style view for tvOS.

KBBulletinView Bulletin / 'Toast' style view for tvOS. This project is an effort to create local application notifications/alerts similar to those use

Kevin Bradley 4 Nov 26, 2022
A modern iOS toast view that can fit your notification needs

CRToast CRToast is a library that allows you to easily create notifications that appear on top of or by pushing out the status bar or navigation bar.

Collin Ruffenach 4.2k Dec 30, 2022
A Simple Toast Library for iOS

PowerplayToastKit Toasts Type Success. Warning Error Info Custom View (Dialog) Example To run the example project, clone the repo, and run pod install

Mithilesh Parmar 18 Jul 2, 2022
A Swift extension that adds toast notifications to the UIView object class.

Toast-Swift Toast-Swift is a Swift extension that adds toast notifications to the UIView object class. It is intended to be simple, lightweight, and e

Charles Scalesse 3.3k Dec 22, 2022
🍞 Toast for Swift

Toaster Android-like toast with very simple interface. (formerly JLToast) Screenshots Features Queueing: Centralized toast center manages the toast qu

Suyeol Jeon 1.6k Dec 30, 2022
CoffeeToast - A swift package to easily add Toast notifications to your app

CoffeeToast A simple Swift package to add Toast Notifications to your app. Insta

Maegan Wilson 2 Feb 3, 2022
LCToast - Add toast to UIView.

LCToast Add toast to UIView. Requirements iOS 8.0+ Features The LCToast is a comparison of features with Toast and SVProgressHUD. LCToast Toast SVProg

LiuChang 158 Nov 22, 2022
A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

donggyu 5 Jan 26, 2022
JAlert - This is "Alert View" project for UIKit + SwiftUI. you can use easily

JAlert Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation JAlert is a

Jackson 3 Feb 22, 2022
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Orderella Ltd. 3.8k Dec 20, 2022
(Experimental libraries) Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI.

UIPresentCoordinator Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI. This library manages items that are

Yuki Tamazawa 1 Jan 22, 2022
A fully customizable popup style menu for iOS 😎

Guide Check out the documentation and guides for details on how to use. (Available languages:) English įŽ€äŊ“中文 What's a better way to know what PopMenu o

Cali Castle 1.5k Dec 30, 2022
A simple style messages/notifications, in Swift.

Demo Example To show notifications use the following code: self.showMessage("Something success", type: .success) To display a notice on a view: view.s

Gesen 704 Dec 17, 2022
SwiftMessages is a very flexible view and view controller presentation library for iOS.

SwiftMessages Overview SwiftMessages is a very flexible view and view controller presentation library for iOS. Message views and view controllers can

SwiftKick Mobile 6.7k Jan 2, 2023
Swift Package mimicking UIKit's ActionSheet with added features

ActionSheetController A Swift package that mimics the UIAlertController Actionsheet with added features. ActionSheetController gives you the ability t

Adebiyi Mojisola 5 Sep 4, 2021
It is a highly configurable iOS library which allows easy styling with built in styles as well as extra header and footer views so that you can make extremely unique alerts and action sheets.

īŖŋ CFAlertViewController CFAlertViewController is a library that helps you display and customise Alerts, Action Sheets, and Notifications on iPad and i

Crowdfire Inc. 1.1k Dec 18, 2022
A SwiftUI wrapper of the new UIKit sheetPresentationController's capabilities in iOS15.

BottomSheet Bring to SwiftUI the UIKit bottom sheet capabilities that came with iOS15. Usage Show the bottom sheet Button(action: { show.toggle() }) {

Kaww 8 Dec 29, 2022
A crisp in-app notification/message banner built in Swift.

RMessage Screenshots Intro Welcome to RMessage! RMessage is a simple notification library written in Swift to help you display notification on the scr

Adonis Peralta 407 Nov 29, 2022
zekunyan 608 Dec 30, 2022