有什么办法可以 swift 地烘烤吐司消息吗?

我已经在目标c中进行了尝试,但没有 swift 找到解决方案。

[self.view makeToast:@"Account created Successfully"
                     duration:0.5
                     position:@"bottom"];

最佳答案

extension UIViewController {

func showToast(message : String, font: UIFont) {

    let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 75, y: self.view.frame.size.height-100, width: 150, height: 35))
    toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
    toastLabel.textColor = UIColor.white
    toastLabel.font = font
    toastLabel.textAlignment = .center;
    toastLabel.text = message
    toastLabel.alpha = 1.0
    toastLabel.layer.cornerRadius = 10;
    toastLabel.clipsToBounds  =  true
    self.view.addSubview(toastLabel)
    UIView.animate(withDuration: 4.0, delay: 0.1, options: .curveEaseOut, animations: {
         toastLabel.alpha = 0.0
    }, completion: {(isCompleted) in
        toastLabel.removeFromSuperview()
    })
} }
像这样使用:
self.showToast(message: "Your Toast Message", font: .systemFont(ofSize: 12.0))

关于ios - 如何在Swift中 toast 消息?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31540375/

10-09 09:52