我想在Swift中使数组定义标签,但是当我尝试这样做并且运行该应用程序时,它们只是不显示。我的视图控制器代码就在这里:进口UIKit的Swift:标签没有显示
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.
}
}
'tipLabel.center = CGPointMake(CGFloat的(我* 50 + 150),0)',为什么?你没有足够的设置框架?此外,你的意思是'tipLabel.center = CGPointMake(CGFloat(i * 50 + 150),15)' – Larme