setNeedsLayout vs. setNeedsUpdateConstraints and layoutIfNeeded vs updateConstraintsIfNeeded

I know that the auto layout chain consists in basically 3 different process. updating constraints layout views (here is where we get calculation of frames) display What’s is not totally clear to me is the inner difference between -setNeedsLayout and -setNeedsUpdateConstraints. From Apple Docs: setNeedsLayout Call this method on your application’s main thread when you … Read more

How to add constraints programmatically using Swift

I’m trying to figure this out since last week without going any step further. Ok, so I need to apply some constraints programmatically in Swift to a UIView using this code: var new_view:UIView! = UIView(frame: CGRectMake(0, 0, 100, 100)); new_view.backgroundColor = UIColor.redColor(); view.addSubview(new_view); var constX:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: … Read more