0
votes

I started using autolayout and my UIViewController's self.view no longer takes up the whole screen for iPhone 6 or iPhone 6plus. The size of the UIView is size = inferred.

I've looked under constraints for the main view of my VC and the constraint editor does not let me select that I want a distance of 0,0,0,0 for the top,left,right, and bottom of the view to the edge of the window.

1

1 Answers

0
votes

I made a function to add a white mask under a UIView (if you are subclassing UIView)

func addBackgroundMask(){
    backgroundMask = UIView()
    backgroundMask?.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.6)
    backgroundMask?.setTranslatesAutoresizingMaskIntoConstraints(false)

    let topConstraint = NSLayoutConstraint(item: backgroundMask!, attribute:NSLayoutAttribute.Top, relatedBy:NSLayoutRelation.Equal, toItem:superview, attribute:NSLayoutAttribute.Top, multiplier:1.0, constant:0.0)

    let bottomConstraint = NSLayoutConstraint(item: backgroundMask!, attribute:NSLayoutAttribute.Bottom, relatedBy:NSLayoutRelation.Equal, toItem:superview, attribute:NSLayoutAttribute.Bottom, multiplier:1.0, constant:0.0)

    let leftConstraint = NSLayoutConstraint(item: backgroundMask!, attribute:NSLayoutAttribute.Left, relatedBy:NSLayoutRelation.Equal, toItem:superview, attribute:NSLayoutAttribute.Left, multiplier:1.0, constant:0.0)

    let rightConstraint = NSLayoutConstraint(item: backgroundMask!, attribute:NSLayoutAttribute.Right, relatedBy:NSLayoutRelation.Equal, toItem:superview, attribute:NSLayoutAttribute.Right, multiplier:1.0, constant:0.0)

    superview?.insertSubview(backgroundMask!, belowSubview: self)

    superview?.addConstraint(topConstraint)
    superview?.addConstraint(bottomConstraint)
    superview?.addConstraint(leftConstraint)
    superview?.addConstraint(rightConstraint)

}