I need to know if there is any method in iOS which behaves like Toast messages in Android. That is, I need to display a message which is dismissed automatically after few se
For the ones that using Xamarin.IOS you can do like this:
new UIAlertView(null, message, null, "OK", null).Show();
using UIKit; is required.
Again if using IOS on Xamarin there is a new component called BTProgressHUD in the component store
For Swift 3 & 4:
Use Toaster library
Toast(text: "Hello, world!", duration: Delay.long)
For Swift 2:
Use JLToast
For me this solution works fine: https://github.com/cruffenach/CRToast
Example how use it:
NSDictionary *options = @{
kCRToastTextKey : @"Hello World!",
kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
kCRToastBackgroundColorKey : [UIColor redColor],
kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight)
};
[CRToastManager showNotificationWithOptions:options
completionBlock:^{
NSLog(@"Completed");
}];
You can make use of MBProgressHUD project.
Use HUD mode MBProgressHUDModeText
for toast-like behaviour,
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
// Configure for text only and offset down
hud.mode = MBProgressHUDModeText;
hud.label.text = @"Some message...";
hud.margin = 10.f;
hud.yOffset = 150.f;
hud.removeFromSuperViewOnHide = YES;
[hud hideAnimated:YES afterDelay:3];
Swift Implementation of Android Toast using Alert which dissipate after 3 secs.
func showAlertView(title: String?, message: String?) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(3 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
print("Bye. Lovvy")
alertController.dismissViewControllerAnimated(true, completion: nil)
}
}
To Call it simply :
self.showAlertView("Message sent...", message: nil)