我正在尝试以编程方式向视图contactsView
添加标签,但是由于某种原因,它没有被添加。这是我的代码,我什么也没收到,但什么也没得到。
我尝试在viewWillAppear
中调用getContacts(),但仍然没有实现
class ModuleViewController: UIViewController {
@IBOutlet weak var contactsView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
getContacts()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
fileprivate func getContacts() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 285)
label.textAlignment = .center
label.textColor = .black
label.text = "Test"
self.contactsView.addSubview(label)
}
}
答案 0 :(得分:1)
问题是这一行:
label.center = CGPoint(x: 160, y: 285)
它会将标签移出您无法查看的联系人视图。