Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

HituziANDO/MKAToastView

Repository files navigation

[NOTE] This project moved to https://github.com/HituziANDO/MKAPopupKit

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

  1. Download latest MKAToastView
  2. Drag & Drop MKAToastView.framework into your Xcode project

Usage

  1. Import the module

    Objective-C

    #import <MKAToastView/MKAToastView.h>

    Swift

    import MKAToastView
  2. 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.

About

MKAToastView is the view that disappears automatically after displaying a short message for a few seconds like Android's Toast.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published