How to Toast message in Swift?

后端 未结 22 1015
暖寄归人
暖寄归人 2020-12-22 19:18

Is there any way to Toast message in swift ?

I have tried in objective c but could not find solution in swift.

[self.view makeToast:@\"Account create         


        
22条回答
  •  礼貌的吻别
    2020-12-22 19:55

    If the need is for a simple Toast message without fancy customization of font, alignment, text color, etc. then the following would do just fine

    let messageVC = UIAlertController(title: "Message Title", message: "Account Created successfully" , preferredStyle: .actionSheet)
    present(messageVC, animated: true) {
                    Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { (_) in
                        messageVC.dismiss(animated: true, completion: nil)})}
    

    .actionSheet presents the alert from Bottom of the screen and the Timer takes care of the display duration. You can add this as an extension to UIViewController and then call it from anywhere.

提交回复
热议问题