利用GCD和UILabel實現,代碼如下
//設置登錄成功提示
let label = UILabel.init(frame: CGRect.init(x: 50, y: 667 - 30 - 64 - 64, width: 375 - 100, height: 20))
label.text = "登錄成功"
label.font = UIFont.systemFont(ofSize: 15)
label.backgroundColor = UIColor.gray
label.textAlignment = .center
label.layer.cornerRadius = 4
label.layer.masksToBounds = true
mtvc.view.addSubview(label)
DispatchQueue.global().async {
Thread.sleep(forTimeInterval: 2)//延時2秒執行
//回到主線程
DispatchQueue.main.async {
label.removeFromSuperview()
}
}
_ = self.navigationController?.popToViewController(mtvc, animated: true)