美文网首页
Swift -- 展示某个信息

Swift -- 展示某个信息

作者: 嗯哼丶傻大个是你 | 来源:发表于2017-03-20 15:22 被阅读0次
      fileprivate func showAlert(_ message: String, width: CGFloat) {
        let alertView = UIView(frame: CGRect(x: 0, y: 0, width: WIDTH - width, height: 60))
        alertView.layer.cornerRadius = 20
        alertView.backgroundColor = UIColor.black
        alertView.alpha = 0.8
        let alertLabel = UILabel(frame: CGRect(x: 0, y: 0, width: WIDTH - width, height: 40))
        alertLabel.text = message
        alertLabel.font = UIFont(name: "PingFangSC-Medium", size: 18)
        alertLabel.textAlignment = .center
        alertLabel.textColor = UIColor.white
        alertView.addSubview(alertLabel)
        alertView.center = view.center
        alertLabel.center = CGPoint(x: (WIDTH - width) / 2, y: 30)
        view.addSubview(alertView)
        
        UIView.animate(withDuration: 0.2, animations: {
          alertView.alpha = 0.8
        }, completion: { _ in
          UIView.animate(withDuration: 2.0, animations: {
            alertView.alpha = 0.0
          }, completion: { _ in
            alertView.removeFromSuperview()
          })
        })
      }
    
    

    相关文章

      网友评论

          本文标题:Swift -- 展示某个信息

          本文链接:https://www.haomeiwen.com/subject/zwxinttx.html