If I create a standard UIView let aView = UIView() and add constraints to it programmatically the view will show on the screen.
However, if I create a custom view that inherits from UIView class CustomView: UIView then instantiate this view let aView = CustomView() and add constraints to it, the view does not appear on the screen.
But if I add instantiate the custom view with a frame let aView = CustomView(frame: CGRectMake(0,0,100,100)) the custom view will appear.
Do you have to supply a frame to a custom view for it to show on the screen?
Updated:
My constraints are
let leftConstraint: NSLayoutConstraint = NSLayoutConstraint(item: aView, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Left, multiplier: 1.0, constant: 50)
let topConstraint: NSLayoutConstraint = NSLayoutConstraint(item: aView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 0)
let rightConstraint: NSLayoutConstraint = NSLayoutConstraint(item: aView, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Right, multiplier: 1.0, constant: 0)
let bottomConstraint: NSLayoutConstraint = NSLayoutConstraint(item: aView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 20)
I would like not to have to specify width and height constraints and just let the edges determine the size of the view.
Can this be done?
aViewwhen it's not appearing and someone might be able to help.