๐Ÿž Toast for Swift - Toaster Android-like toast with very simple interface

Related tags

UI swift ios toast
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 8+ projects with CocoaPods:

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

    github "devxoul/Toaster"
    
  • For iOS 8+ 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
ToastSwiftUI-master - A simple way to show a toast or a popup in SwiftUI

ToastSwiftUI-master - A simple way to show a toast or a popup in SwiftUI

Kushal Shingote 2 May 25, 2022
A replacement of default action sheet, but has very simple usage

KPActionSheet A replacement of default action sheet, but has very simple usage. Todo Add more custom affects and styles. Installation CocoaPods KPActi

Kenny 7 Jun 27, 2022
Peanut is an orginizational application focusing on user customization whithin a simple interface.

Peanut Peanut is an organizational application focusing on user customization within a simple interface. Table of Contents User Features Architecture

Adam Herring 2 Mar 2, 2022
List tree data souce to display hierachical data structures in lists-like way. It's UI agnostic, just like view-model and doesn't depend on UI framework

SwiftListTreeDataSource List tree data souce to display hierachical data structures in lists-like way. It's UI agnostic, just like view-model, so can

Dzmitry Antonenka 26 Nov 26, 2022
User Interface Library for iOS

Why Sejima Because in modern mobile applications, you often reuse user interface components. To avoid code duplication, we have tried to provide you w

Move Upwards 64 Dec 22, 2022
UI framework that allows developers to integrate an amazing selection interface into their applications

UI framework that allows developers to integrate an amazing selection interface into their applications! Each bubble has a set of parameters, which could be configured individually.

AJIJIi 5 Jul 12, 2022
A simple Elm-like Store for SwiftUI, based on ObservableObject

ObservableStore A simple Elm-like Store for SwiftUI, based on ObservableObject.

Gordon Brander 28 Nov 8, 2022
You can dismiss modal viewcontroller like Facebook Messenger by pulling scrollview or navigationbar in Swift.

PullToDismiss PullToDismiss provides dismiss modal viewcontroller function like Facebook Messenger by pulling scrollview or navigationbar with smooth

Suguru Kishimoto 479 Dec 5, 2022
๐Ÿ” Awesome fully customize search view like Pinterest written in Swift 5.0 + Realm support!

YNSearch + Realm Support Updates See CHANGELOG for details Intoduction ?? Awesome search view, written in Swift 5.0, appears search view like Pinteres

Kyle Yi 1.2k Dec 17, 2022
A fancy hexagonal layout for displaying data like your Apple Watch

Hexacon is a new way to display content in your app like the Apple Watch SpringBoard Highly inspired by the work of lmmenge. Special thanks to zenly f

Gautier Gรฉdoux 340 Dec 4, 2022
A horizontal scroll dial like Instagram.

HorizontalDial Preview Requirements iOS 8.0+ Swift 5 Storyboard support Installation CocoaPods use_frameworks! pod "HorizontalDial" Manually To instal

Lee Sun-Hyoup 210 Nov 22, 2022
RangeSeedSlider provides a customizable range slider like a UISlider.

RangeSeekSlider Overview RangeSeekSlider provides a customizable range slider like a UISlider. This library is based on TomThorpe/TTRangeSlider (Objec

WorldDownTown 644 Dec 12, 2022
SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationContoller. Support 3D Touch!

SAHistoryNavigationViewController Support 3D Touch for iOS9!! SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationConto

Taiki Suzuki 1.6k Dec 29, 2022
Full configurable spreadsheet view user interfaces for iOS applications. With this framework, you can easily create complex layouts like schedule, gantt chart or timetable as if you are using Excel.

kishikawakatsumi/SpreadsheetView has moved! It is being actively maintained at bannzai/SpreadsheetView. This fork was created when the project was mov

Kishikawa Katsumi 34 Sep 26, 2022
A window arrangement manager for macOS like BetterSnapTool and Magnet

A window arrangement manager for macOS like BetterSnapTool and Magnet. You can split the foremost window to the left half of the screen, the left two-thirds, etc.

Takuto NAKAMURA (Kyome) 65 Dec 9, 2022
A SwiftUI bottom-up controller, like in the Maps app. Drag to expand or minimize.

SwiftUI Drawer A SwiftUI bottom-up controller, like in the Maps app. Drag to expand or minimize. Contents Add the Package Basic Usage Examples Credits

Michael Verges 695 Jan 3, 2023
Add the Notch on the menubar like the new MacBook Pro.

iNotch Add the Notch on the menubar like the new MacBook Pro. Installation This app works on macOS 11.0 or later. Download iNotch.zip from releases pa

Takuto NAKAMURA (Kyome) 8 Apr 3, 2022
Fully customizable Facebook reactions like control

Reactions is a fully customizable control to give people more ways to share their reaction in a quick and easy way. Requirements โ€ข Usage โ€ข Installatio

Yannick Loriot 585 Dec 28, 2022