Skip to content

Instantly share code, notes, and snippets.

@tixster
Created December 29, 2023 15:02
Show Gist options
  • Select an option

  • Save tixster/7ab3441c7d414667979a32ce01beb05d to your computer and use it in GitHub Desktop.

Select an option

Save tixster/7ab3441c7d414667979a32ce01beb05d to your computer and use it in GitHub Desktop.
UsesAutoLayout
@propertyWrapper
public struct UsesAutoLayout<T: UIView> {
public var wrappedValue: T {
didSet {
_setTranslatesAutoresizingMaskIntoConstraints()
}
}
public init(wrappedValue: T) {
self.wrappedValue = wrappedValue
_setTranslatesAutoresizingMaskIntoConstraints()
}
private func setTranslatesAutoresizingMaskIntoConstraints() {
wrappedValue.translatesAutoresizingMaskIntoConstraints = false
}
}
// Usage:
class MyView: UIView {
@UsesAutoLayout var button: UIButton
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment