/JLToast

:bread: Toast for Swift - Android-like toast with simple interface.

Primary LanguageSwiftDo What The F*ck You Want To Public LicenseWTFPL

JLToast - Toast for Swift

Swift 2.0 CocoaPods Carthage compatible

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.3'
  • 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.3.5', :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)

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.