【发布时间】:2018-12-30 21:54:15
【问题描述】:
我已经编写了一个函数,它定义并添加了一个 UILabel 到 UIView - 但是约束没有被执行,因为标签仍然在屏幕的左上角。
代码如下:
func timeAdded(screenHeight: CGFloat, screenWidth: CGFloat, viewController: UIView) {
let readyLabel = UILabel()
readyLabel.backgroundColor = UIColor.white
readyLabel.textAlignment = .center
readyLabel.text = "00:00"
readyLabel.textColor = UIColor.blue
//readyLabel.alpha = 0
readyLabel.font = UIFont(name: "panl-font-4", size: 60)
readyLabel.sizeToFit()
viewController.addSubview(readyLabel)
readyLabel.centerXAnchor.constraint(equalTo: viewController.centerXAnchor, constant: 0).isActive = true
readyLabel.centerYAnchor.constraint(equalTo: viewController.centerYAnchor, constant: 0).isActive = true
}
任何建议表示赞赏
【问题讨论】:
标签: ios swift constraints