Is it possible for the secondary view to automatically change in the storyboard, since the changes in "view as" change?

I have a view controller with a secondary view that looks like this in a storyboard when viewed as an iPhone 7

enter image description here

But if I switch to iPhone SE view, it looks like this: enter image description here

Is it possible for it to automatically change in the storyboard in the same way as view controllers?

+4
source share
2 answers

... -, ? , . UIView, , . ( , ) " Visual Format" /NSLayoutConstraint .

MyCustomView ( -) UIView. UIViewController , .

1) MyCustomView, ( - ):

let alertView = MyCustomView(frame: CGRect(0,0,200,150))

self.view.addSubview(alertView)

alertView.constrainToSuperView()

2) constrainToSuperView :

private func constrainToSuperView() {

    self.translatesAutoresizingMaskIntoConstraints = false

    var constraints = [NSLayoutConstraint]()

    let vertical = NSLayoutConstraint.constraints(withVisualFormat: "V:|[self]|", options: [], metrics: nil, views: ["self": self])

    constraints.append(contentsOf: vertical)

    let horizontal = NSLayoutConstraint.constraints(withVisualFormat: "H:|[self]|", options: [], metrics: nil, views: ["self": self])

    constraints.append(contentsOf: horizontal)

    self.superview.addConstraints(constraints)

}

, , . .

1: MyCustomView. . . , .xib . , - .

2: , . , , .

, . .

0

Source: https://habr.com/ru/post/1675654/


All Articles