Last active
September 13, 2019 23:51
-
-
Save bielikb/85b6211be1258b1bf9781eed8ddfbbad to your computer and use it in GitHub Desktop.
Use Autolayout
This file contains hidden or 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
@propertyWrapper | |
public struct UseAutoLayout<T: UIView> { | |
var value: T | |
public var wrappedValue: T { | |
get { return value } | |
set { self.value.translatesAutoresizingMaskIntoConstraints = false } | |
} | |
public init(wrappedValue: T) { | |
value = wrappedValue | |
} | |
} | |
final class ViewController: UIViewController { | |
@UseAutoLayout var label = UILabel() | |
override func viewDidLoad() { | |
label = UILabel() | |
label.backgroundColor = .yellow | |
label.textAlignment = .center | |
self.view.addSubview(label) | |
label.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true | |
label.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true | |
label.text = "autolayout" | |
print("translatesAutoresizingMaskIntoConstraints: \(view.translatesAutoresizingMaskIntoConstraints)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment