A fully customizable library to easily display Animated Toast Messages in iOS using Swift!

Overview

CustomToastView-swift

CI Status Version License Platform

A fully customizable library to easily display Animated Toast Messages in iOS using Swift!

Preview - All the custom toasts you can build!

Requirements

Installation

CustomToastView-swift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CustomToastView-swift'

Usage

In order to build your custom toast you need to use the Toast builder class. The following example shows a Custom Toast on a View Controller class with the default style and a default animation from bottom to top.

Toast.Builder()
     .build()
     .show(on: self)

Here's an example with a completion from when the user taps the toast:

Toast.Builder()
     .build()
     .show(on: self) { toast in
          toast.hide()
     }

Also Toast.Builder() could be stored as a constant class for later usage:

let toastBuilder = Toast.Builder()

Animation Types

You can present your Toast messages in different ways:

  • from bottom to top (.bottomToTop)
  • from top to bottom (.topToBottom)
  • from left to right (.leftToRight)
  • from right to left (.rightToLeft)
  • fading in (.fadeIn)
  • fading out (.fadeOut)

The only thing you need to do is to specify the orientation (Animation type) when building your toast, as follows:

Toast.Builder()
     .orientation(.leftToRight)
     .build()
     .show(on: self)

Specifying Vertical position

In order to set the y position in which the Toast should display we use the .verticalPosition property and set the Int value you want, as follows:

Toast.Builder()
     .verticalPosition(150)
     .build()
     .show(on: self)

Toast Height

You might want to change the defautl Toast Height. In case you'd need to that you can do it as follows:

Toast.Builder()
     .toastHeight(100)
     .build()
     .show(on: self)

Toast - BackgroundColor, TextColor, Font, Title, CornerRadius, TextAlignment

All the following properties are customizable as well in case the default values are not useful to you !

 Toast.Builder()
      .font(UIFont.systemFont(ofSize: 12, weight: .semibold))
      .backgroundColor(.orange)
      .textColor(.white)
      .cornerRadius(12)
      .title("Hello! I'm a toast")
      .orientation(.fadeOut)
      .textAlignment(.right)
      .build()
      .show(on: self)

You can also set a right action on the Toast

To do that you just need to set the following property when building your custom toast!

Toast.Builder()
     .rightActionText("UNDO")
     .build()
     .show(on: self)

You can also set the specific styles for the action:

Toast.Builder()
     .rightActionText("UNDO")
     .actionFont(UIFont.systemFont(ofSize: 12, weight: .medium))
     .actionTextColor(.white)
     .build()
     .show(on: self)

You might want to add a completion to the above 'UNDO' action :) You can do that as follows:

Toast.Builder()
     .rightActionText("UNDO")
     .actionFont(UIFont.systemFont(ofSize: 12, weight: .medium))
     .actionTextColor(.white)
     .build()
     .show(on: self, actionCompletion: {
          print("UNDO action tapped")
     })

Left Icon & letIconContentMode

You might need to set a left icon, in that case this is the way to do it:

 Toast.Builder()
      .font(UIFont.systemFont(ofSize: 18, weight: .semibold))
      .backgroundColor(.success)
      .showLeftIcon(UIImage(named: "check"))
      .textColor(.white)
      .title("Possible success message!")
      .textAlignment(.left)
      .build()
      .show(on: self)

letIconContentMode is the propety to set the contentMode to the left icon image added:

 Toast.Builder()
      .font(UIFont.systemFont(ofSize: 18, weight: .semibold))
      .backgroundColor(.success)
      .showLeftIcon(UIImage(named: "check"))
      .letIconContentMode(.scaleAspectFill)
      .textColor(.white)
      .title("Possible success message!")
      .textAlignment(.left)
      .build()
      .show(on: self)

The default value of letIconContentMode is .scaleAspectFit

Default Distance

This property allows you to change the lateral margins of your toast. If you increase this value the width of the toast will decrease. You can set this side margin in the following way:

Toast.Builder()
     .defaultDistance(30)
     .build()
     .show(on: self)

The default value of defaultDistance is 16

Should Dismiss After Presenting

This property specifies if the Toast should dismiss automatically after presenting or not. The default value of shouldDismissAfterPresenting is set to true. In case you don't want the toast to dismiss automatically after presenting you should implement the following:

 Toast.Builder()
      .shouldDismissAfterPresenting(false)
      .build()
      .show(on: self)

If you'd like to hide the toast when user taps it, you should call the hide function on the completion, as follows:

 Toast.Builder()
      .shouldDismissAfterPresenting(false)
      .build()
      .show(on: self) { toast in
          toast.hide()
      }

Time Dismissal (in seconds)

Time dismissal is the property that indicates the time in seconds you want the Toast to take to dismiss itself (in case you want the toast to dismiss after a certain period of time). The default value is 0.5 seconds.

Toast.Builder()
     .timeDismissal(1)
     .build()
     .show(on: self)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Author

lrodriguez, [email protected]

License

CustomToastView-swift is available under the MIT license. See the LICENSE file for more info.

You might also like...
SNPnotificationBar - Notification Bar for ios
SNPnotificationBar - Notification Bar for ios

SNPnotificationBar Screenshot Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements S

🚎 Simple type-safe event bus implementation in swift

🚎 RealEventsBus RealEventsBus is a small swift experiment package to implement a basic type-safe event bus mechanism. Some other implementations in G

🍞 An async waiting toast with basic toast. Inspired by facebook posting toast
🍞 An async waiting toast with basic toast. Inspired by facebook posting toast

AwaitToast 🍞 An async waiting toast with basic toast. Inspired by facebook posting toast. Introduction Usage Default let toast: Toast = Toast.default

🍞 Toast for Swift - Toaster Android-like toast with very simple interface
🍞 Toast for Swift - Toaster Android-like toast with very simple interface

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

The SwiftUI Messages Clone consists of layout and composition clones of the iOS Messages app.
The SwiftUI Messages Clone consists of layout and composition clones of the iOS Messages app.

The SwiftUI Messages Clone consists of layout and composition clones of the iOS Messages app. It has Messages-like bubble and screen effects, reactions, and animations, all created with SwiftUI.

A fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. Written in Swift.
A fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. Written in Swift.

DTPagerController This is a control for iOS written in Swift. DTPagerController is simple to use and easy to customize. Screenshots Default segmented

A fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. Written in Swift.
A fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. Written in Swift.

DTPagerController This is a control for iOS written in Swift. DTPagerController is simple to use and easy to customize. Screenshots Default segmented

DTPhotoViewerController - A fully customizable photo viewer ViewController to display single photo or collection of photos, inspired by Facebook photo viewer.
DTPhotoViewerController - A fully customizable photo viewer ViewController to display single photo or collection of photos, inspired by Facebook photo viewer.

DTPhotoViewerController Example Demo video: https://youtu.be/aTLx4M4zsKk DTPhotoViewerController is very simple to use, if you want to display only on

Whisper is a component that will make the task of display messages and in-app notifications simple. It has three different views inside
Whisper is a component that will make the task of display messages and in-app notifications simple. It has three different views inside

Description 🍃 Break the silence of your UI, whispering, shouting or whistling at it. Whisper is a component that will make the task of displaying mes

Weatherflow-local - Basic frame-out of a SwiftUI macOS app to receive & display WeatherFlow UDP broadcast messages
Weatherflow-local - Basic frame-out of a SwiftUI macOS app to receive & display WeatherFlow UDP broadcast messages

WeatherFlow Local A very basic/skeleton SwiftUI macOS app for receiving and disp

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

UIProgressView replacement with an highly and fully customizable animated progress bar in pure Core Graphics
UIProgressView replacement with an highly and fully customizable animated progress bar in pure Core Graphics

The YLProgressBar is an UIProgressView replacement with a highly and fully customizable animated progress bar in pure Core Graphics. It has been imple

💌 Easy to use and customizable messages/notifications for iOS à la Tweetbot

Notice: TSMessages is no longer being maintained/updated. We recommend everyone migrate to RMessage. This repository will be kept as is for those who

A Simple Toast Library for iOS
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

SwiftEntryKit is a presentation library for iOS. It can be used to easily display overlays within your iOS apps.
SwiftEntryKit is a presentation library for iOS. It can be used to easily display overlays within your iOS apps.

SwiftEntryKit 🤗 Donations can be made here. Table of Contents Overview Features Example Project Example Project Installation Presets Playground Requi

SwiftEntryKit is a presentation library for iOS. It can be used to easily display overlays within your iOS apps.
SwiftEntryKit is a presentation library for iOS. It can be used to easily display overlays within your iOS apps.

SwiftEntryKit 🤗 Donations can be made here. Table of Contents Overview Features Example Project Example Project Installation Presets Playground Requi

A fully customizable iOS Horizontal PickerView library, written in pure swift
A fully customizable iOS Horizontal PickerView library, written in pure swift

ADDatePicker is Horizontal Date Picker Library written in Swift Requirements Communication Installation Usage Demo Customization Credits License Requi

A fully customizable iOS calendar library, compatible with Objective-C and Swift
A fully customizable iOS calendar library, compatible with Objective-C and Swift

Table of contents Screenshots Installation Pre-knowledge Support Contact Screenshots iPhone iPad Safe Orientation Today Extension iOS8/9 iOS10 Interac

A smooth, responsive and flexible messages UI library for iOS.
A smooth, responsive and flexible messages UI library for iOS.

AsyncMessagesViewController A smooth, responsive and flexible messages UI library for iOS apps. Built on top of the awesome Texture (formerly AsyncDis

Comments
  • Getting  'Ambiguous use of' error when using toast.hide() method

    Getting 'Ambiguous use of' error when using toast.hide() method

    toast.hide() is giving me Ambiguous use of 'hide()'

    //Code where i m facing this

    func customToast(index:Int){         
        if let titleStr = responeDetail.roomTypes?[0].roomType?[index].additionalDetails{
            toastBuilder
                .font(UIFont.systemFont(ofSize: 12, weight: .semibold))
                .backgroundColor(.flatOrange)
                .showLeftIcon(UIImage(systemName: "info"))
                .textColor(.white)
                .orientation(.topToBottom)
                .title(titleStr)
                .shouldDismissAfterPresenting(false)
                .build()
                .show(on: self) { toast in
                    toast.hide() // Here getting that error using "hide()"
                }
        }
    
    }
    
    Screenshot 2022-03-09 at 9 29 07 AM
    opened by Pgmr-sagar 1
Owner
Leticia Rodriguez
Computer Science Engineer
Leticia Rodriguez
Library to send mock remote notifications to the iOS simulator

SimulatorRemoteNotifications SimulatorRemoteNotifications is a library to send mock remote notifications to the iOS simulator. The library extends UIA

Arnaud Coomans 1.4k Dec 20, 2022
FNotify - Notification Library For iOS

FNotify Notification Library For IOS FNotify.mov Requirements: xcode 12+ swift 5

Frameworks 1 Jan 9, 2022
A Swift Library for Dynamic Island Push Notification.

Push Notification With Dynamic Island Handle Push Notification with Dynamic Island ?? Descreption: Since there is not library for Apple Push Notificat

Amir Diafi 5 Nov 12, 2022
Push notifications allow developers to reach users, even when users aren't actively using an app!

Push notifications allow developers to reach users, even when users aren't actively using an app! With the latest update of iOS Apple provide very useful extensions which are user-friendly. In this tutorial, I am going to share the configuration, set up of Notification with the media attachments like.

MindInventory 16 Mar 3, 2022
APNSUtil is makes code simple using apple push notification service

APNSUtil APNSUtil makes code simple settings and landing for apple push notification service. Features Using apple push notification service simply No

Steve Kim 30 Mar 24, 2022
SystemNotification is lets you mimic the native iOS system notification in your SwiftUI apps.

SystemNotification is a SwiftUI library that lets you mimic the native iOS system notification in your iOS apps.

Daniel Saidi 153 Dec 22, 2022
Push Notification Registration for iOS

Orbiter Note: This project is no longer being maintained. For most iOS client / server applications, push notifications are negotiated through an inte

Mattt 672 Nov 17, 2022
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

Pusher OS X and iOS application and framework to play with the Apple Push Notification service (APNs) Installation Install the Mac app using Homebrew

noodlewerk 6.2k Dec 22, 2022
Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS

FocusPlsNoBadges Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS, in a really gross and hacky way. Getting started Build the X

Ayden Panhuyzen 18 Dec 14, 2022
Chanify is a safe and simple notification tools. This repository is iOS clinet for Chanify.

Chanify English | įŽ€äŊ“中文 Chanify is a safe and simple notification tools. For developers, system administrators, and everyone can push notifications wit

Chanify 156 Jan 4, 2023