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 seconds. This is similar to the functionality of the Toast class in the Android environment.

推荐答案

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];

enter image description here

Ios相关问答推荐

如何将模糊输入/模糊输出添加到SwiftUI中的非对称过渡?

Xcode 15模拟器用x86_64编译

OBJC @selector 在另一个实现中不起作用

如何将 Info.plist 文件添加到 Xcode for admob,错误 添加后会产生多个命令

在自定义 ButtonStyle 中修改形状 colored颜色

如果使用 .onAppear 设置,为什么 SwiftUI Picker 不显示正确的选定值

拔下设备后,DriverKit USB 驱动程序 (dext) 进程不会终止

为 ColorPicker 创建一个名为 Color 的计算变量的绑定

SwiftUI Select 器值在超过最大值时重置

从远程通知启动时,iOS 应用程序加载错误

Swift 共享数据模型在页面之间进行通信.这个怎么运作

将 SwiftUI 与 @AppStorage 和动态函数调用一起使用

如何在 Swift 上的 sendSynchronousRequest 中判断 Response.statusCode

是否可以在没有 Mac 的情况下为 iOS 制作 PhoneGap 应用程序?

构建失败:ld:重复符号 _OBJC_CLASS_$_Algebra5FirstViewController

无法验证客户端 3000

如何使用 Contacts Framework 获取 iOS 9 中的所有联系人记录

命令 /Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang 失败,退出代码为 1

在 iOS 上编写文件

在 iOS 7 中更改返回按钮会禁用滑动导航返回