【发布时间】:2018-02-18 21:46:43
【问题描述】:
我想显示一个包含一些固定文本的弹出窗口。
我为弹出窗口找到了这个。
// 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()
}
}
我似乎无法在 showAlert() 中添加标签并显示它。
我尝试在 showAlert 中调用一个单独的函数来获取标签文本,该函数有效,但不会关闭。
如何在 showAlert 函数本身的弹出窗口中添加文本/字符串/标签?我想使用 UIView 本身,而不是 AlertController。
【问题讨论】:
-
您在哪里尝试添加标签?
标签: ios swift text swift3 popup