我想显示一个弹出窗口,其中包含一些固定文本。
我为弹出窗口找到了这个。
// Define a view
var popup:UIView!
func showAlert() {
// customise your view
popup = UIView(frame: CGRect(x: 100, y: 200, width: 200, height: 200))
popup.backgroundColor = UIColor.redColor
// show on screen
self.view.addSubview(popup)
// set the timer
Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: #selector(self.dismissAlert), userInfo: nil, repeats: false)
}
func dismissAlert(){
if popup != nil { // Dismiss the view from here
popup.removeFromSuperview()
}
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法在 showAlert() 中添加标签并显示它。
我尝试在 showAlert 中调用一个单独的函数来获取标签文本,该函数可以工作,但不会关闭。
如何将文本/字符串/标签添加到 showAlert 函数本身的弹出窗口中?我想使用 UIView 本身,而不是 AlertController。