Skip to content

Instantly share code, notes, and snippets.

@kelvinfok
Created April 1, 2023 17:19
Show Gist options
  • Save kelvinfok/418687f02175fa4214c9df8d724b717b to your computer and use it in GitHub Desktop.
Save kelvinfok/418687f02175fa4214c9df8d724b717b to your computer and use it in GitHub Desktop.
UIKit UILabel Builder Pattern Extension
extension UILabel {
func resizable() -> Self {
translatesAutoresizingMaskIntoConstraints = false
return self
}
func text(_ text: String) -> Self {
self.text = text
return self
}
func align(_ alignment: NSTextAlignment) -> Self {
textAlignment = alignment
return self
}
func font(_ font: UIFont) -> Self {
self.font = font
return self
}
func textColor(_ color: UIColor) -> Self {
self.textColor = color
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment