Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a view in Storyboard's scene dock be adaptive?

Xcode 7 allows a view to be added to a scene dock. However, the documentation does not specify how that scene can be made adaptive so it changes its form factor depending on the size class of your device. The view is not relative to any superview so there is no way for it to be constrained to a superview.

How do you make a view in Storyboard's scene dock be adaptive?

like image 865
Boon Avatar asked Feb 12 '16 13:02

Boon


1 Answers

Create an outlet in the code and add constraints programmatically. For example:

    let margins = self.view.layoutMarginsGuide
    yourView.translatesAutoresizingMaskIntoConstraints = false
    yourView.leadingAnchor.constraint(equalTo: margins.leadingAnchor).isActive = true
    yourView.trailingAnchor.constraint(equalTo: margins.trailingAnchor).isActive = true

    yourView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 20.0).isActive = true


    yourView.heightAnchor.constraint(equalToConstant: 260.0).isActive = true
like image 137
David Lindsay Avatar answered Oct 30 '22 07:10

David Lindsay