Giter VIP home page Giter VIP logo

loaf's Introduction

Loaf ๐Ÿž

Inspired by Android's Toast,
Loaf is a Swifty Framework for Easy iOS Toasts

Version Liscence Platform Swift4.2


Usage

From any view controller, a Loaf can be presented by calling:

Loaf("Message goes here", sender: self).show()

Which will result in:

screen shot 2019-02-27 at 3 59 07 pm

Bellow, I will discuss how to further customize your Loaf!

Playground

I've provided an example project to showcase uses of Loaf! Simply clone this repo, and open LoafExamples.xcodeproj. From here you can see and experiment custom Loaf styles in Examples.swift

Customization

Basic styles

Loaf comes with 4 basic style out of the box.

Success Error
screen shot 2019-02-27 at 3 45 44 pm screen shot 2019-02-27 at 3 45 52 pm
Warning Info
screen shot 2019-02-27 at 3 45 58 pm screen shot 2019-02-27 at 3 53 26 pm

These styles can be specified in the style property. For instance, to use Success styled Loaf, call it like so:

Loaf("This is a success loaf", state: .success, sender: self).show()

Custom styles

Loaf allows you to specify a custom style! This will let you set the colors, font, icon. and icon alignment. Here are some examples of custom Loaf styles!

Colors and icon Right icon alignment No icon
screen shot 2019-02-27 at 6 09 33 pm screen shot 2019-02-27 at 6 13 13 pm screen shot 2019-02-27 at 6 13 22 pm

All of these properties are specified as part of custom state, like so:

Loaf("Switched to light mode", state: .custom(.init(backgroundColor: .black, icon: UIImage(named: "moon"))), sender: self).show()

Presenting and dismissing

Loaf allows you to specify the presenting and dismissing direction. The presenting direction is independant from the dismissal direction. Here are some examples:

Vertical Left
vertical left
Right Mix
right mix

These are specified in the function signature, like so:

Loaf("Loaf message", presentingDirection: .left, dismissingDirection: .vertical, sender: self).show()

Location

Toasts are typically presented at the bottom of the screen, but Loaf allows you to also present them at the top of the screen. Here is an example of a Loaf being presented at the top of the view:

screen shot 2019-02-27 at 8 30 04 pm

This is also specified in the function signature, like so:

Loaf("Loaf message", location: .top, sender: self).show()

Other

Specify the presentation duration. When presenting a Loaf with .show(), a presentation duration can be specified. The default value is 4s, but there are presets for 2s and 8s. This is done by using .show(.short) for 2s, or .show(.long) for 8s. A custom duration can also be specified with .show(.custom(x)), where x represents the duration in seconds.

โš ๏ธ New in 0.3.0:

A completion handler can be specified in the Loaf show() function signature. This block will be called when the dismissal animation is completed. Here is an example of using a completion handler, now named onTap:

Loaf(example.rawValue, sender: self).show {
     print("Dismissed!")
}

Installation

Cocoapods

Loaf is on Cocoapods! After setting up Cocoapods in your project, simply add the folowing to your Podfile:

pod 'Loaf'

then run pod install from the directory containing the Podfile!

Don't forget to include import Loaf in every file you'd like to use Loaf

Requirements

  • Swift 4.2+
  • iOS 11.0+

Contributing

Pull requests, feature requests and bug reports are welcome ๐Ÿš€


Thanks to @kirkbyo for helping me through the tough parts of this ๐Ÿ’ช

Made with โค๏ธ in ๐Ÿ‡จ๐Ÿ‡ฆ by Mat Schmid

loaf's People

Watchers

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