Coder Social home page Coder Social logo

2ank3th / jltoast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from devxoul/toaster

0.0 2.0 0.0 631 KB

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

License: Do What The F*ck You Want To Public License

Ruby 2.71% Objective-C 6.28% Swift 91.01%

jltoast's Introduction

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.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.0', :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.

jltoast's People

Contributors

devxoul avatar hardtack avatar kimdarren avatar fahimf avatar butcheryl avatar cbot avatar dkhamsing avatar itlijunjie avatar

Watchers

James Cloos avatar Sanketh Purwar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.