ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - schmidyy/Loaf: 🍞 A Swifty Framework for Easy iOS Toasts
🍞 A Swifty Framework for Easy iOS Toasts . Contribute to schmidyy/Loaf development by creating an account on GitHub.
Visit Site

GitHub - schmidyy/Loaf: 🍞 A Swifty Framework for Easy iOS Toasts

GitHub - schmidyy/Loaf: 🍞 A Swifty Framework for Easy iOS Toasts


Usage

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

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

Which will result in:

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
Warning Info

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

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:

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.5.0:

  • A completion handler can be specified in the Loaf show() function signature. This block will be called when the dismissal animation is completed, or when the Loaf is tapped. This completion handler is now passed with a enum representing whether the Loaf was tapped or timmed out. Here is an example of using a completion handler:
Loaf(example.rawValue, sender: self).show { dismissalType in
     switch dismissalType {
          case .tapped: print("Tapped!")
          case .timedOut: print("Timmed out!")
     }
}
  • A Loaf's width can be specified via the Style component. The width can be specifed as a fixed size (i.e. 280px) or as a percentage of the screen's width. (i.e. 0.8 -> 80%). Here is some example usage:
Loaf(example.rawValue, state: .custom(.init(backgroundColor: .black, width: .screenPercentage(0.8))), sender: self).show()
  • Loaf's will now be presented above tab bars, when possible.
  • Loaf's can be manually dismissed through a global method:
Loaf.dismiss(sender: self) // Where `self` is the Loaf's presenter

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 9.0+

Contributing

Pull requests, feature requests and bug reports are welcome 🚀


Thanks to @kirkbyo for helping me through the tough parts of this 💪

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory