Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schmidyy/Loaf
🍞 A Swifty Framework for Easy iOS Toasts
https://github.com/schmidyy/Loaf
Last synced: 3 days ago
JSON representation
🍞 A Swifty Framework for Easy iOS Toasts
- Host: GitHub
- URL: https://github.com/schmidyy/Loaf
- Owner: schmidyy
- License: mit
- Created: 2019-02-04T23:17:35.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-25T08:57:37.000Z (over 1 year ago)
- Last Synced: 2024-11-30T13:03:53.573Z (12 days ago)
- Language: Swift
- Homepage:
- Size: 116 KB
- Stars: 1,094
- Watchers: 15
- Forks: 101
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Loaf - A simple framework for easy iOS Toasts. (UI / Alert & Action Sheet)
- awesome-swift - Loaf - A simple framework for easy iOS Toasts. (Libs / UI)
- awesome-swift - Loaf - A simple framework for easy iOS Toasts. (Libs / UI)
- awesome-ios - Loaf - A Swifty Framework for Easy iOS Toasts. [•](https://user-images.githubusercontent.com/22358682/53522566-a2b1f880-3aa8-11e9-8451-f555811f85ed.png) (Content / Alert)
- awesome-ios-star - Loaf - A simple framework for easy iOS Toasts. (UI / Alert & Action Sheet)
- fucking-awesome-swift - Loaf - A simple framework for easy iOS Toasts. (Libs / UI)
- awesome-swift - Loaf - A Swifty Framework for Easy iOS Toasts ` 📝 8 months ago` (UI [🔝](#readme))
README
Loaf 🍞
Inspired by Android's Toast,
Loaf is a Swifty Framework for Easy iOS Toasts____
## Usage
From any view controller, a Loaf can be presented by calling:
```swift
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:
```swift
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:
```swift
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](https://user-images.githubusercontent.com/22358682/53534239-f71a9f80-3acb-11e9-8010-c7915012a187.gif) | ![left](https://user-images.githubusercontent.com/22358682/53534240-f7b33600-3acb-11e9-8b10-b6d2cb3199a2.gif) || Right | Mix |
| ---- | ---- |
| ![right](https://user-images.githubusercontent.com/22358682/53534241-f7b33600-3acb-11e9-8e55-457c5a2f32d2.gif) | ![mix](https://user-images.githubusercontent.com/22358682/53534242-f7b33600-3acb-11e9-9e74-88653d469746.gif) |These are specified in the function signature, like so:
```swift
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:
```swift
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:
```swift
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:
```Swift
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:```swift
Loaf.dismiss(sender: self) // Where `self` is the Loaf's presenter
```____
## Installation
### Cocoapods
Loaf is on Cocoapods! After [setting up Cocoapods in your project](https://guides.cocoapods.org/), 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](https://github.com/kirkbyo) for helping me through the tough parts of this 💪
Made with ❤️ in 🇨🇦 by Mat Schmid