Git Product home page Git Product logo

gttoast's Introduction

GTToast

CI Status Version License Platform

GTToast is a library written in Swift which allows toast notifcations to be displayed. You can create toasts with text and/or images. There are many options available to allow you to adapt look and feel of the toast messages to your app.

Preview

Usage

There are multiple ways you can display toast message:

  • Simple toast
GTToast.create("your message").show()

This will create and show toast with default settings and your message

  • Simple toast with image
GTToast.create("your message", image: yourImage).show()

This will create and show toast with your message and image displayed on the left.

  • Custom toast
GTToast.create("your message", config: GTToastConfig(), image: yourImage).show()

This will create and show toast with message and custom config. You can find all properties of GTToastConfig below

  • All toasts with the same configuration

You can specify global configuration for all of your toast.

let config: GTToastConfig = GTToastConfig()
let toastFactory: GTToast = GTToast(config: config)
toastFactory.create("your message").show()
toastFactory.create("your message", image: smallImage).show()

Configuration

You can use GTToastConfig to configure the look of the toast. Here is a list of all possible configuration options that can be specified:

  • contentInsets: UIEdgeInsets

Allows you to specify the padding of the toast. Default: UIEdgeInsets(top: 3.0, left: 3.0, bottom: 3.0, right: 3.0)

  • cornerRadius: CGFloat

The corner radius of the toast. Default 3.0

  • font: UIFont

Font used to render the text message. Default: UIFont.systemFontOfSize(12.0)

  • textColor: UIColor

Text color of the message. Default: UIColor.whiteColor()

  • textAlignment: NSTextAlignment

Alignment of the text. Default: NSTextAlignment.Center

  • backgroundColor: UIColor

Background color of the toast. Default: UIColor.blackColor().colorWithAlphaComponent(0.8)

  • animation: GTToastAnimation

The animation type to be used when displaying and hidding the toast. Default: GTToastAnimation.BottomSlideIn (see below for full list)

  • displayInterval: NSTimeInterval

The amount of time the toast will be displayed for: Default: 4

  • bottomMargin: CGFloat

Bottom margin of the toast. Default: 5

  • imageMargins: UIEdgeInsets

The margins of the image displayed in the toast. Default: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

  • imageAlignment: GTToastAlignment

Allows you to specify where image should be displayed (Top, Bottom, Left or Right). Default: GTToastAlignment.Left

  • maxImageSize: CGSize

Specifes the max image size. The width property is only into account when image is located on the Right or Left. Similarly, the height is only applied when image in Top or Bottom. Default: CGSize(width: 100, height: 200)

You can specify all of the above by creating GTToastConfig

GTToastConfig(
    contentInsets: UIEdgeInsets(top:10, left: 9, bottom: 8, right: 7),
    cornerRadius: 8.0,
    font: UIFont.systemFontOfSize(100),
    textColor: UIColor.redColor(),
    textAlignment: NSTextAlignment.Right,
    backgroundColor: UIColor.blueColor().colorWithAlphaComponent(0.8),
    animation: GTToastAnimation.Scale,
    displayInterval: 2,
    bottomMargin: 15.0,
    imageMargins: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10),
    imageAlignment: GTToastAlignment.Top,
    maxImageSize: CGSizeMake(100,100)
)

Only the properties that you want to change can be provided. No need for all of them.

GTToastAnimation options

GTToastAnimation hold predefined list of animations that can be used for displaying the toast

  • Alpha
  • Scale
  • BottomSlideIn
  • LeftSlideIn
  • RightSlideIn
  • LeftInRightOut
  • RightInLeftOut

Requirements

This control is written in Swift 2. You will need at least XCode 7. Also this project uses Cocoapods.

Installation

Install GTToast by using CocoaPods. Include the following in your Podfile:

use_frameworks!
pod 'GTToast'

Running the project

After cloning the project you will need to run 'pod update' in the Example directory. To view in XCode open the GTToast.xcworkspace which is located in the Example directory.

Author

Grzegorz Tatarzyn, [email protected]

License

GTToast is available under the MIT license.

gttoast's People

Contributors

gregttn avatar

Watchers

woshizilong 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.