JLToast 1.4.2

JLToast 1.4.2

TestsTested
LangLanguage SwiftSwift
License Custom
ReleasedLast Release Sep 2016
SPMSupports SPM

Maintained by Suyeol Jeon.


Downloads

Total371,422
Week253
Month949

Installs

Apps3,023
Apps WeekApps This Week 45
Test Targets205
Test WeekTests This week 2
powered by Segment

GitHub

Stars806
Watchers33
Forks92
Issues5
Contributors16
Pull Requests0

Code

Files5
LOCLines of Code 416


JLToast 1.4.2

  • By
  • devxoul

JLToast - Toast for Swift

Android-like toast with very simple interface.

At a Glance

JLToast.makeText("Some text").show()

Features

  • Objective-C Compatible: import JLToast.h to use JLToast in Objective-C.
  • Queueing: centralized toast center manages toast queue.
  • Customizable: see Appearance section.

Installation

  • For iOS 8+ projects with CocoaPods:

    pod 'JLToast', '~> 1.4'
  • For iOS 8+ projects with Carthage:

    github "devxoul/JLToast" ~> 1.0
    
  • For iOS 7 projects: I recommend you to try CocoaSeeds, which uses source code instead of dynamic frameworks. Sample Seedfile:

    github 'devxoul/JLToast', '1.4.2', :files => 'JLToast/*.{swift,h}'

Objective-C

JLToast is compatible with Objective-C. What you need to do is to import a auto-generated header file:

#import <JLToast/JLToast-Swift.h>

If you are looking for constants, import JLToast.h.

#import <JLToast/JLToast-Swift.h>
#import <JLToast/JLToast.h> // if you want to use constants

Setting Duration and Delay

JLToast.makeText("Some text", duration: JLToastDelay.LongDelay)
JLToast.makeText("Some text", delay: 1, duration: JLToastDelay.ShortDelay)

Removing Toasts

  • Removing toast with reference:

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

    if let currentToast = JLToastCenter.defaultCenter.currentToast {
        currentToast.cancel()
    }
  • Removing all toasts:

    JLToastCenter.defaultCenter.cancelAllToasts()

Appearance

Since JLToast 1.1.0, you can set default values for appearance attributes. The code below sets default background color to red.

Note: It is not recommended to set default values while toasts are queued. It can occur unexpected results.

Swift

JLToastView.setDefaultValue(
    UIColor.redColor(),
    forAttributeName: JLToastViewBackgroundColorAttributeName,
    userInterfaceIdiom: .Phone
)

Objective-C

[JLToastView setDefaultValue:[UIColor redColor]
            forAttributeName:JLToastViewBackgroundColorAttributeName
          userInterfaceIdiom:UIUserInterfaceIdiomPhone];

Supported Attributes

Attribute Type Description
JLToastViewBackgroundColorAttributeName UIColor Background color
JLToastViewCornerRadiusAttributeName NSNumber(CGFloat) Corner radius
JLToastViewTextInsetsAttributeName NSValue(UIEdgeInsets) Text inset
JLToastViewTextColorAttributeName UIColor Text color
JLToastViewFontAttributeName UIFont Font
JLToastViewPortraitOffsetYAttributeName NSNumber(CGFloat) Vertical offfset from bottom in portrait mode
JLToastViewLandscapeOffsetYAttributeName NSNumber(CGFloat) Vertical offfset from bottom in landscape mode

Screenshots

JLToast Screenshot

License

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