Created
May 13, 2021 08:04
-
-
Save muukii/71056d7985618587e4bdf7ca4c695db1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class ZStackView: UIView { | |
public init(views: [UIView]) { | |
super.init(frame: .zero) | |
views.forEach { view in | |
addSubview(view) | |
view.translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
view.leftAnchor.constraint(greaterThanOrEqualTo: self.leftAnchor), | |
view.topAnchor.constraint(greaterThanOrEqualTo: self.topAnchor), | |
view.rightAnchor.constraint(lessThanOrEqualTo: self.rightAnchor), | |
view.bottomAnchor.constraint(lessThanOrEqualTo: self.bottomAnchor), | |
{ | |
let c = view.centerXAnchor.constraint(equalTo: self.centerXAnchor) | |
c.priority = .defaultLow | |
return c | |
}(), | |
{ | |
let c = view.centerYAnchor.constraint(equalTo: self.centerYAnchor) | |
c.priority = .defaultLow | |
return c | |
}(), | |
]) | |
} | |
setContentHuggingPriority(.defaultHigh, for: .horizontal) | |
setContentHuggingPriority(.defaultHigh, for: .vertical) | |
} | |
public required init?(coder: NSCoder) { | |
fatalError() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment