๐Ÿž Toast for Swift

Overview

Toaster

Build Status Swift CocoaPods Carthage compatible

Android-like toast with very simple interface. (formerly JLToast)

Screenshots

Toaster Screenshot

Features

  • Queueing: Centralized toast center manages the toast queue.
  • Customizable: See the Appearance section.
  • String or AttributedString: Both supported.
  • UIAccessibility: VoiceOver support.

At a Glance

import Toaster

Toast(text: "Hello, world!").show()

Installation

  • For iOS 9+ projects with CocoaPods:

    pod 'Toaster'
  • For iOS 9+ projects with Carthage:

    github "devxoul/Toaster"
    
  • For iOS 9+ and Xcode 11+ projects with Swift Package Manager:

    dependencies: [
        .package(url: "https://github.com/devxoul/Toaster.git", from: "master")
    ]
    

Getting Started

Setting Duration and Delay

Toast(text: "Hello, world!", duration: Delay.long)
Toast(text: "Hello, world!", delay: Delay.short, duration: Delay.long)

Removing Toasts

  • Removing toast with reference:

    let toast = Toast(text: "Hello")
    toast.show()
    toast.cancel() // remove toast immediately
  • Removing current toast:

    if let currentToast = ToastCenter.default.currentToast {
        currentToast.cancel()
    }
  • Removing all toasts:

    ToastCenter.default.cancelAll()

Appearance

Since Toaster 2.0.0, you can use UIAppearance to set default appearance. This is an short example to set default background color to red.

ToastView.appearance().backgroundColor = .red

Supported appearance properties are:

Property Type Description
backgroundColor UIColor Background color
cornerRadius CGFloat Corner radius
textInsets UIEdgeInsets Text inset
textColor UIColor Text color
font UIFont Font
bottomOffsetPortrait CGFloat Vertical offfset from bottom in portrait mode
bottomOffsetLandscape CGFloat Vertical offfset from bottom in landscape mode
shadowPath CGPath The shape of the layerโ€™s shadow
shadowColor UIColor The color of the layerโ€™s shadow
shadowOpacity Float The opacity of the layerโ€™s shadow
shadowOffset CGSize The offset (in points) of the layerโ€™s shadow
shadowRadius CGFloat The blur radius (in points) used to render the layerโ€™s shadow
maxWidthRatio CGFloat The width ratio of toast view in window
useSafeAreaForBottomOffset Bool A Boolean value that determines safeAreaInsets.bottom is added to bottomOffset

Attributed string

Since Toaster 2.3.0, you can also set an attributed string:

Toast(attributedText: NSAttributedString(string: "AttributedString Toast", attributes: [NSAttributedString.Key.backgroundColor: UIColor.yellow]))

Accessibility

By default, VoiceOver with UIAccessibility is enabled since Toaster 2.3.0. To disable it:

ToastCenter.default.isSupportAccessibility = false

License

Toaster is under WTFPL. You can do what the fuck you want with Toast. See LICENSE file for more info.

Comments
  • Toast message view did not rotate on iPad mini.

    Toast message view did not rotate on iPad mini.

    In iPad mini (iOS 9.3.1), when we rotate device from portrait to landscape mode, toast message did not rotate with latest version of JLToast(1.4.1). In older JLToast(1.0), it is working fine. In iPad air the version of JLToast(1.4.1) also working as expected. Please find attach screenshot for more reference.

    img_0079

    opened by suniljakhar 24
  • Toast is showing vertically in Landscape iPad

    Toast is showing vertically in Landscape iPad

    error

    JLToastView.setDefaultValue(
                UIColor.redColor(),
                forAttributeName: JLToastViewBackgroundColorAttributeName,
                userInterfaceIdiom: .Pad
            )
            let toast = JLToast.makeText("Testing Toast long toast long toast long toast..")
            toast.show()
    
    opened by SSamanta 17
  • ์„ค์น˜๋ฒ•์ด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜์š”?

    ์„ค์น˜๋ฒ•์ด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜์š”?

    ์•ˆ๋…•ํ•˜์„ธ์š”. ์ดˆ๋ณด ์•„์ดํฐ ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค.

    ์–ด๋–ป๊ฒŒ ์„ค์น˜ํ•ด์•ผ ํ•˜๋‚˜์š”? Podfile์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ pod 'JLToast', '~> 1.3'๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ํ„ฐ๋ฏธ๋„์—์„œ pod install์„ ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค. Podsํด๋”์•ˆ์— JLToast ํŒŒ์ผ๋“ค์€ ๋“ค์–ด๊ฐ”๋Š”๋ฐ ViewController์—์„œ JLToast.makeText("Basic JLToast").show()๋ฅผ ์ž…๋ ฅํ•˜๋‹ˆ JLToast๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๊ณ  ํ•˜๋„ค์š”.

    ๋ญ๊ฐ€ ์ž˜๋ชป๋œ ๊ฑธ๊นŒ์š”? ๋„์›€ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

    opened by goodsogi 15
  • Prevent crash when using a NativeScript app (for alternate icon name)

    Prevent crash when using a NativeScript app (for alternate icon name)

    After showing a Toast my app would crash when using this method.

    I have very little experience in Swift so I don't know why the rootViewController getter needs to be hijacked by this pod, but to make it work for my case I'd really love to have this code merged.

    opened by EddyVerbruggen 14
  • v1.3.2 changes statusbar text color from white to black

    v1.3.2 changes statusbar text color from white to black

    Just noticed that when the toast appears the status bar text color changes from white to black. Statusbar style is set to UIStatusBarStyleLightContent in info.plist.

    opened by artworkad 13
  • Toast appears behind keyboard, not visible to user

    Toast appears behind keyboard, not visible to user

    If the software keyboard is visible toast message appear behind the keyboard not in front of it.

    Use case: validation of text inside text field. You want the keyboard to be present however you also want to display a toast. BUT the toast should not block interaction with keyboard.

    opened by artworkad 9
  • Add shadow appearance

    Add shadow appearance

    appearance.shadow = ToastShadow(color: UIColor.black.cgColor, opacity: 0.2, offset: CGSize(width: 0, height: 1), raidus: 10)
    

    | Without Shadow | With Shadow | |--- |--- | | | |

    enhancement 
    opened by cozzin 7
  • Crash

    Crash

    While on iPad simulator I received this crash:

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSOperationInternal _start:]: something is trying to start the receiver simultaneously from more than one thread' *** First throw call stack: ( 0 CoreFoundation 0x0000000113438b0b exceptionPreprocess + 171 1 libobjc.A.dylib 0x0000000112e9d141 objc_exception_throw + 48 2 CoreFoundation 0x00000001134a1625 +[NSException raise:format:] + 197 3 Foundation 0x00000001129a5599 -[__NSOperationInternal _start:] + 277 4 Toaster 0x00000001109aefc4 TFC7Toaster5Toast5startfT_T + 132 5 Toaster 0x00000001109af2ac TFFC7Toaster5Toast5startFT_T_U_FT_T + 108 6 Toaster 0x00000001109af2f7 TTRXFo___XFdCb + 39 7 libdispatch.dylib 0x00000001144574a6 _dispatch_call_block_and_release + 12 8 libdispatch.dylib 0x000000011448005c _dispatch_client_callout + 8 9 libdispatch.dylib 0x000000011446140b _dispatch_main_queue_callback_4CF + 411 10 CoreFoundation 0x00000001133fd909 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 11 CoreFoundation 0x00000001133c3ae4 __CFRunLoopRun + 2164 12 CoreFoundation 0x00000001133c3016 CFRunLoopRunSpecific + 406 13 GraphicsServices 0x0000000115dc8a24 GSEventRunModal + 62 14 UIKit 0x0000000110a0b0d4 UIApplicationMain + 159 15 carpolo 0x000000010b4485b7 main + 55 16 libdyld.dylib 0x00000001144cc65d start + 1 17 ??? 0x0000000000000008 0x0 + 8 ) libc++abi.dylib: terminating with uncaught exception of type NSException

    opened by mn288 7
  • Toast Doesn't Appear Inside CollectionView didSelectItemAtIndexPath

    Toast Doesn't Appear Inside CollectionView didSelectItemAtIndexPath

    I have a UICollectionView where I let the user select up to 5 photos. After 5 are selected I'm trying to show a toast message informing the user only 5 photos can be selected. I am using JLToast throughout the code, however here it does not show. The UICollectionView is within a UIViewController. Here is the code I am using within didSelectItemAtIndexPath:

            println("show toast")
            JLToast.makeText(NSLocalizedString("select_up_to_five_photos", comment: "Select up to 5 photos")).show()            
    

    The println gets printed correctly, but I don't see a toast.

    opened by mikewalkerjr 7
  • SWRevealViewController ์™€์˜ UIbarStyle ๋ฌธ์ œ

    SWRevealViewController ์™€์˜ UIbarStyle ๋ฌธ์ œ

    SWRevealViewController ( https://github.com/John-Lluch/SWRevealViewController) ) ๋กœ ๋งŒ๋“  frontView์™€ rearView ์—์„œ์˜ UIBarStyle ์˜ ์†์„ฑ ๊ฐ’์ด ๋‹ค๋ฅผ ๋•Œ Front(.Black) ์™€ Rear(.Default) ๋ฅผ ์˜ค๊ฐˆ ๋•Œ statusBar ๊ฐ€ ์ž๋™์œผ๋กœ ์Šคํƒ€์ผ์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค๋งŒ, ๋ทฐ ๋‚ด์—์„œ JLToas๋ฅผ ํ†ตํ•œ toast ๋ฅผ ํ•œ๋ฒˆ์ด๋ผ๋„ ๋„์šธ ์‹œ, Rear ๋ทฐ์˜ statusBar ๊ฐ€ Front ๋ทฐ์˜ statusBar ์†์„ฑ๊ฐ’์œผ๋กœ ๊ณ ์ •๋ฉ๋‹ˆ๋‹ค.

    ์‚ฌ์ง„์„ ์ฒจ๋ถ€ํ•  ๊ณณ์ด ์—†์–ด ๊ฐœ์ธ ๋ธ”๋กœ๊ทธ๋กœ ์‚ฌ์ง„์ฒจ๋ถ€๋ฅผ ๋Œ€์‹  ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค http://ceno-loid.tistory.com/45

    I built a project with SWRevealViewController (LINK) and JLToast. When the property of rearViewโ€™s UIBarStyle is different from frontViewโ€™s one (rearViewBarStyle: .Default, frontViewBarStyle: .Black) UIStatusBar changes its own style itself, but if JLToast is shown more than one time on view, frontViewโ€™s UIBarStyle overrides rearViewโ€™s one.

    Here is the link, the photo posted with my own blog. LINK

    opened by CenoX 6
  • Xcode 13.3.1: no Package.swift manifest for version 2.3.0

    Xcode 13.3.1: no Package.swift manifest for version 2.3.0

    Did add package using repo url and version up to next major. When trying to build the project, an error occurs Showing All Messages /Package.swift has no Package.swift manifest for version 2.3.0 in https://github.com/devxoul/Toaster

    opened by gezamiklo 5
  • Add custom backgroundView width option

    Add custom backgroundView width option

    I want to change backgroundview's width value so I add custom backgroundview width option to ToastView.swift now can change width like this

    appearance.backgroundWidth = NSNumber(value: self.view.frame.width - 32.0)
    
    opened by amebahead 0
  • On iOS 15, when the keyboard is displaying, toasts don't display until I hide and display the keyboard again.

    On iOS 15, when the keyboard is displaying, toasts don't display until I hide and display the keyboard again.

    Hi, in the demo project, I reproduce the bug.

    1. Click the Toggle keyboard button to show the keyboard
    2. Click the Show button to show a toast, then the toast displays behind the keyboard window scene.

    Do you have any idea that can fix this ?

    opened by hvnwnd 0
  • Error when using

    Error when using "Picture in Picture".

    Environment: Xcode 12.4 (12D4e) Language: Swift 5.3.2 Toaster version used: 2.3.0

    When using the "Picture in Picture" function on iOS 14 or higher devices, the toast view is not in the normal position.

    Error reproduction path:

    1. Launch the video player(AVPlayer) and activate the PIP mode.
    2. Change the device orientation to landscape mode.
    3. Change the orientation back to portrait.
    • An error occurred.

    When an error occurs, the toast is output in a strange position, regardless of the device's orientation portrait/landscape.

    IMG_16BC596BD6AD-1

    Looking at the code, let containerSize = ToastWindow.shared.frame.size in ToastView's layoutSubviews() is wrong. Originally it should be the device screen size, but it seems to be returned as the size of AVLayer of AVPictureInPictureController.

    opened by HyunjoonKo 0
  • Question: multiple appearance

    Question: multiple appearance

    Hello :)

    just a quick question, is it possible to set multiple appearances for multiple kinds of toasts ? I have no idea to manage this currently

    Thx !

    opened by PierreBrisorgueil 0
Releases(2.3.0)
Owner
Suyeol Jeon
A lazy developer ๐Ÿ˜ด I write many code to write less code.
Suyeol Jeon
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
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
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
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
Swift library to manage in app notification in swift language, like WhatsApp, Telegram, Frind, ecc.

InAppNotify - Manage in App notifications During develop of my app Frind, I needed to manage in app notifications like whatsapp or telegram, but i did

Luca Becchetti 438 Nov 20, 2022
Ipraktikum-swift-solutions - The solutions of the easy entrance swift quiz for the IPraktikum

ipraktikum-swift-solutions The solutions of the easy entrance swift quiz for the

Eugenio Berretta 0 Feb 13, 2022
Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift

CDAlertView is highly customizable alert popup written in Swift. Usage is similar to UIAlertController. Screenshots Animations Usage Basic usage witho

Candost Dagdeviren 1.1k Dec 30, 2022
Easy Swift UIAlertController

EZAlertController Easy Swift UIAlertController One line setup for all UIAlertControllers Button action with closures instead of selectors Easily custo

Kan Yilmaz 366 Sep 14, 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
A Swift library to provide a bouncy action sheet

Hokusai is a Swift library that provides a bouncy action sheet. It will give the users a fancy experience without taking pains coding the cool animati

Yuta Akizuki 430 Nov 20, 2022
Simple UIAlertController builder class in Swift.

Kamagari Simple UIAlertController builder class in Swift. Features AlertBuilder class to simply build UIAlertController by using method chaining UIAle

Kazunobu Tasaka 78 Nov 29, 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
Beautiful animated Alert View. Written in Swift

SCLAlertView Animated Alert View written in Swift, which can be used as a UIAlertView or UIAlertController replacement. Since UIAlertView is deprecate

Viktor Radchenko 5.2k Jan 3, 2023
Live animated Alert View for iOS written in Swift

Sweet Alert iOS Beautiful Animated custom Alert View inspired from javascript library SweetAlert. Written in Swift this SweetAlertView can be used in

Sahil 2k Dec 22, 2022
A Swift library to design custom prompts with a great scope of options to choose from.

Installation CocoaPods Install with CocoaPods by adding the following to your Podfile: source 'https://github.com/CocoaPods/Specs.git' platform :ios,

Gabriel Alvarado 736 Nov 3, 2022
SwiftOverlays is a Swift GUI library for displaying various popups and notifications

SwiftOverlays is a Swift GUI library for displaying various popups and notifications. SwiftOverlays animated logo is kindly made by Crafted Pixels Fea

Peter Prokop 632 Dec 22, 2022