I have a single window with a single custom view in it, and I want the custom view to resize with the window so that it entirely fills it at any time. If I write:
You can create constraints with Layout Anchors with very easy to read format:
Swift2 code
func fit(childView: UIView, parentView: UIView) {
childView.translatesAutoresizingMaskIntoConstraints = false
childView.topAnchor.constraintEqualToAnchor(parentView.topAnchor).active = true
childView.leadingAnchor.constraintEqualToAnchor(parentView.leadingAnchor).active = true
childView.trailingAnchor.constraintEqualToAnchor(parentView.trailingAnchor).active = true
childView.bottomAnchor.constraintEqualToAnchor(parentView.bottomAnchor).active = true
}
Use:
parrentView.addSubview(childView)
fit(childView, parentView: parrentView)