Created
April 2, 2020 14:11
-
-
Save aainaj/e967ab29e60d2206b65510bfb3799b5b to your computer and use it in GitHub Desktop.
UILabel builder pattern
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
extension UILabel { | |
static func build(block: ((UILabel) -> Void)) -> UILabel { | |
let label = UILabel(frame: .zero) | |
label.translatesAutoresizingMaskIntoConstraints = false | |
block(label) | |
return label | |
} | |
} | |
var label: UILabel { | |
return UILabel.build { label in | |
label.text = "Hello wold!" | |
label.font = UIFont.systemFont(ofSize: 12) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment