Swift -- 展示某个信息

  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 -- 展示某个信息)