Skip to content

abdullahselek/ASToast

Repository files navigation

Build Status CocoaPods Compatible Carthage Compatible Coverage Status Platform License

ASToast

A Swift extension for using Android style Toast notifications. You may call ASToast methods directly from your view objects.

Screenshots

single_toast image_toast activity_toast

Requirements

ASToast Version Minimum iOS Target Swift Version
1.1.2 9.0 4.1
1.1.1 9.0 4.0
1.1.0 8.0 3.x
1.0.3 8.0 2.x

iOS 8.0+

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate ASToast into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'ASToast', '~> 1.1.2'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

brew update
brew install carthage

To integrate ASToast into your Xcode project using Carthage, specify it in your Cartfile:

github "abdullahselek/ASToast" ~> 1.1.2

Run carthage update to build the framework and drag the built ASToast.framework into your Xcode project.

Example Usage

make a toast with single text with default background color and custom message color

self.view.makeToast(message: "Single text toast",
					backgroundColor: nil,
					messageColor: UIColor.cyan)

make a toast with custom background color white message color

self.view.makeToast(message: "Single text toast",
					backgroundColor: UIColor.blue,
					messageColor: nil)

make a toast with text, title, position, duration and custom colors

self.view.makeToast(message: "Toast with custom text, title and duration",
					duration: TimeInterval(3.0),
					position: .center,
					title: "Title",
					backgroundColor: UIColor.blue,
					titleColor: UIColor.yellow,
					messageColor: UIColor.yellow,
					font: UIFont.systemFont(ofSize: 16))

make toast with an image and custom colors

self.view.makeToast(message: "Toast with an image",
					duration: TimeInterval(3.0),
					position: .top,
					image: UIImage(named: "apple_logo"),
					backgroundColor: UIColor.blue,
					titleColor: UIColor.yellow,
					messageColor: UIColor.yellow,
					font: UIFont.systemFont(ofSize: 16))

Show a custom view as toast

let customView: UIView! = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 300.0))
customView.autoresizingMask = [UIViewAutoresizing.flexibleLeftMargin,
							   UIViewAutoresizing.flexibleRightMargin,
							   UIViewAutoresizing.flexibleTopMargin,
							   UIViewAutoresizing.flexibleBottomMargin]
customView.backgroundColor = UIColor.green

self.view.showToast(toastView: customView,
					duration: TimeInterval(3.0),
					position: .bottom)

Show an imageView as toast, on center at point (110,110)

let toastImageView: UIImageView! = UIImageView(image: UIImage(named: "apple_logo"))
self.view.showToast(toastView: toastImageView,
					duration: TimeInterval(3.0),
					point: CGPoint(x: 110, y: 110))

Show activity indicator

self.view.makeToastActivity()

Hide activity indicator

self.view.hideToastActivity()

MIT License

Copyright (c) 2015 Abdullah Selek

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Credits

Inspired from Charles Scalesse (scalessec). Improved and all coded in new programming 
language Swift.