gpt4 book ai didi

ios - Swift 3 - 向 UIView 弹出窗口添加文本

转载 作者:行者123 更新时间:2023-11-28 15:01:35 24 4
gpt4 key购买 nike

我想显示一个弹出窗口,其中包含一些固定文本。

我为弹出窗口找到了这个。

    // 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。

最佳答案

你可以试试

popup = UIView(frame: CGRect(x: 100, y: 200, width: 200, height: 200))

let lb = UILabel(frame: CGRect(x: 100, y: 200, width: 200, height: 200))
lb.text="anything"
popup.backgroundColor = UIColor.redColor

// show on screen
self.view.addSubview(popup)
popup.addSubview(lb)
lb.center = popup.center

关于ios - Swift 3 - 向 UIView 弹出窗口添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48856944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com