利用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)
网友评论