Hello everyone!
Today I’m going to show you how you can easily create toast in iOS. To achieve this task I’m going to use Charles Scalesse’s Toast API.
First of all download the file from the above link, then add UIView+Toast.h and UIView+Toast.m to your project along with the QuartzCore framework.
As soon as you’ll try adding UIView+Toast.h and UIView+Toast.m to your project a prompt will appear asking to add a bridging-header. Press “YES”. A file ending with -Bridging-Header.h will be available in your project explorer. Open it and write #import “UIView+Toast.h”.
Now lets say you have a button on which on press you want to make a toast for that purpose write the following code in your ViewController.swift or what ever your class name is.
[code language=”css”] @IBAction func simpleToast(sender: AnyObject) {You’re gonna get a result similar to this:
If you want a toast to appear in the center and with a title.
[code language=”css”] @IBAction func positionalToast(sender: UIButton){}
[/code]
This is what you’ll see.
A toast with an image is also possible with this API.
@IBAction func imageToast(sender: AnyObject) { self.view.makeToast("I Love Swift", duration: 5.0, position: CSToastPositionCenter, image: UIImage(named: "swift.png")) }
Resulting toast.
I have made this project, to save time you can download or pull it from my Github.
If you guys have any questions, please leave a comment.
This article covers some important things you must know when you are considering a move…
What is Unit Testing? In its simplest term, unit testing is testing a small piece…
In this article, you will learn about a type of Creational Design Pattern which is…
In this tutorial, you will go through the use of targets to achieve two separate…
In this article, you will learn about a type of Structural Design Pattern which is…
In this article you will learn about a type of Creational Design Pattern which is…