gpt4 book ai didi

arrays - Swift:标签不显示

转载 作者:行者123 更新时间:2023-11-28 15:33:39 25 4
gpt4 key购买 nike

我正在尝试制作由 Swift 中的数组定义的标签,但是当我尝试这样做并运行该应用程序时,它们就是不显示。我的 View Controller 代码就在这里:import UIKit

class SmallPainViewController: UIViewController {

var tips = ["Play your favorite videogame", "Watch a movie", "Watch YouTube"]

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
for (i, tip) in tips.enumerate() {
let tipLabel = UILabel(frame: CGRectMake(CGFloat(i*50+150), 0, 30, 30))
tipLabel.center = CGPointMake(CGFloat(i*50+150), 0)
tipLabel.text = tip
tipLabel.textAlignment = NSTextAlignment.Center
self.view.addSubview(tipLabel)
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}

最佳答案

尝试使用:

var tips = ["Play your favorite videogame", "Watch a movie", "Watch YouTube"]

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
for (i, tip) in tips.enumerated() {
let tipLabel = UILabel(frame: CGRect(x: (i*50+150), y: 150, width: 30, height: 30))//CGRect(CGFloat(i*50+150), 0, 30, 30)
tipLabel.center = CGPoint(x: (i*50+150), y: 150) //CGPoint(CGFloat(i*50+150), 0)
tipLabel.text = tip
tipLabel.textAlignment = NSTextAlignment.center
self.view.addSubview(tipLabel)
}
}

我认为你使用的是 swift 2.0

关于arrays - Swift:标签不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44509584/

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