MKAToastView
MKAToastView is the view that disappears automatically after displaying a short message for a few seconds like Android's Toast.
Include in your iOS app
CocoaPods
MKAToastView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "MKAToastView"
Manual Installation
- Download latest MKAToastView
- Drag & Drop MKAToastView.framework into your Xcode project
Usage
-
Import the module
Objective-C
#import <MKAToastView/MKAToastView.h>
Swift
import MKAToastView
-
Create and show a short message
Objective-C
[MKAToast showText:"@Hello" withTimeInterval:MKAToastShortTime];
Swift
MKAToast.showText("Hello", withTimeInterval: MKAToastShortTime)
Delegate
The toast view calls the delegate methods when it is hidden.
Objective-C
@interface ViewController () <MKAToastDelegate>
@end
@implementation ViewController
...
- (IBAction)helloButtonPressed:(id)sender {
[MKAToast showText:@"Hello"
withDelegate:self
timeInterval:MKAToastShortTime
identifier:1];
}
...
#pragma mark - MKAToastDelegate
- (void)toastWillDisappear:(MKAToast *)toast {
NSLog(@"Toast ID: %ld will disappear", (long) toast.identifier);
}
- (void)toastDidDisappear:(MKAToast *)toast {
NSLog(@"Toast ID: %ld did disappear", (long) toast.identifier);
}
@end
Swift
class ViewController: UIViewController, MKAToastDelegate {
...
@IBAction func helloButtonPressed(_ sender: Any) {
MKAToast.showText("Hello",
with: self,
timeInterval: MKAToastShortTime,
identifier: 1)
}
...
/// MARK: - MKAToastDelegate
func toastWillDisappear(_ toast: MKAToast) {
print("Toast ID: \(toast.identifier) will disappear");
}
func toastDidDisappear(_ toast: MKAToast) {
print("Toast ID: \(toast.identifier) did disappear");
}
}
More info, see my sample project.