Displaying a message in iOS which has the same functionality as Toast in Android

前端 未结 19 1743
逝去的感伤
逝去的感伤 2020-12-12 12:35

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

19条回答
  •  甜味超标
    2020-12-12 13:22

    For Swift 2.0 and considering https://stackoverflow.com/a/5079536/6144027

                    //TOAST
                    let alertController = UIAlertController(title: "", message: "This is a Toast.LENGTH_SHORT", preferredStyle: .Alert)
                    self!.presentViewController(alertController, animated: true, completion: nil)
                    let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2.0 * Double(NSEC_PER_SEC)))
                    dispatch_after(delayTime, dispatch_get_main_queue()) {
                        alertController.dismissViewControllerAnimated(true, completion: nil)
                    }
    

提交回复
热议问题