Reputation: 187
I'm trying to add a label to a view, contactsView
, programmaticly, but for some reason It's not getting added. This is my code, I don't get any error but get nothing.
I have tried call getContacts() in viewWillAppear
but still nothing
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)
}
}
Upvotes: 0
Views: 124
Reputation: 535139
The problem is this line:
label.center = CGPoint(x: 160, y: 285)
It moves the label out of the contacts view where you can’t see it.
Upvotes: 1