How to Toast message in Swift?

后端 未结 22 1219
暖寄归人
暖寄归人 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:47

    @mr-bean code updated to latest Swift version (3.x)

        let toastLabel =
            UILabel(frame:
                CGRect(x: self.view.frame.size.width/2 - 150,
                       y: self.view.frame.size.height-100,
                       width: 300,
                       height: 35))
        toastLabel.backgroundColor = UIColor.black
        toastLabel.textColor = UIColor.white
        toastLabel.textAlignment = NSTextAlignment.center
        self.view.addSubview(toastLabel)
        toastLabel.text = message
        toastLabel.alpha = 1.0
        toastLabel.layer.cornerRadius = 10;
        toastLabel.clipsToBounds  =  true
        UIView.animate(withDuration: 4.0, animations: {
            toastLabel.alpha = 0.0
        })
    

提交回复
热议问题