My take on Toast for iOS (Swift & Objective-C)

Posted by

I know I should hang my head in shame for saying this, but I’ve always liked the Toast popup for Android – just something about its simplicity that makes me think – yeah, that was just how I wanted to be presented with that snippet of information.

Anyway, I recently wanted something similar in one of my iOS apps, purely for debugging purposes too – with this in mind I decided to knock up my own version of Toast for iOS and whilst I was at it, I wrote an Objective-C version too (see one of my recent tweets for my inspiration behind this).

Introducing Crumpet & Bagel for iOS

Yes, I thought of those names all by myself and I’m taking full credit for them, below is a quick run though of Crumpet (Swift version) and how you can use it in your app.

Installation

Simply add the following Swift file to your project

Crumpet.swift

How to use

There are a couple of ways we can use Crumpet;

1.  Add Crumpet to specific UIView, this could be one of multiple Views in your Nib or UIViewController – just simply pass this into the optional parameter as per below.

let specificView = UIView()
Crumpet.shared.pop(message: "Added to a specific View", specificView)

2. Add main view or essentially the ‘first’ window that is found in UIApplication.shared.windows

Crumpet.shared.pop(message: "Added to the Window View")

And that’s really it, fire off the example project found in each repository and you’ll see it in action, it should look something a little like the below;

Customise

If the default speed, wait-time, font & colour are not your cup of tea, you can simply modify these as per the below options;

Crumpet.shared.speed
Crumpet.shared.wait
Crumpet.shared.backgroundColor
Crumpet.shared.textColor
Crumpet.shared.lineCount
Crumpet.shared.font
Crumpet.shared.textAlignment
Crumpet.shared.bottomConstraint

Next steps

I did this just to scratch and itch, but I may look at some other options in the future, such as user interaction further customisation options etc… as with all my git hub projects, contributions and feedback are more than welcome – just grab me on twitter if you want a chat.

Links

Crumpet – https://github.com/MrChrisBarker/crumpet-swift-toast
Bagel – https://github.com/MrChrisBarker/bagel-objectivec-toast

Final note

There are many other alternatives out there but this was just my take in it. Due to this I’ll be keeping this away from dependancy management package such as Cocoapods and SPM for the time being – but who knows, if it gains some traction I may look to ramp it up some more.

Enjoy

C. 🥃