I ve been using storyboards so far to set my constraints but I am attempting to learn how to do things programmatically. The issue at hand:
A table needs to return a cell in cellForRowAt. There I simply need to add a UILabel element that will be constraint to the top left bottom and right anchors. The table cell height is set to automatic as I don't know what the size of the label will be. My code looks as follows:
var uil = UILabel()
cell.addSubview(uil)
uil.leftAnchor.constraint(equalTo: cell.leftAnchor).isActive = true
uil.rightAnchor.constraint(equalTo: cell.rightAnchor).isActive = true
uil.topAnchor.constraint(equalTo: cell.topAnchor).isActive = true
uil.bottomAnchor.constraint(equalTo: cell.bottomAnchor).isActive = true
uil.numberOfLines = 0;
uil.text = "Some variable sized text that could be anything really";
If I don't give a frame to the UILabel I see nothing. If I do however using something like:
UILabel(frame: CGRect(x: 0 , y: 0 , width: 100, height: 100)
Then as expected I see the label but it's like the constraints don't apply.
What am I missing? Shouldn't the constraints be enough as they are fully descriptive?