Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raonivaladares/dfb148ab6be875b036fcbf3e7ea07bd6 to your computer and use it in GitHub Desktop.
Save raonivaladares/dfb148ab6be875b036fcbf3e7ea07bd6 to your computer and use it in GitHub Desktop.
import UIKit
final class UILabelFactory {
private let label: UILabel
private let defultFontSize: CGFloat = 20
// MARK: - Inits
init(text: String) {
label = UILabel()
label.textAlignment = .center
label.text = text
label.font = label.font.withSize(defultFontSize)
label.translatesAutoresizingMaskIntoConstraints = false
}
// MARK: - Public methods
func fontSize(of size: CGFloat) -> Self {
label.font = label.font.withSize(size)
return self
}
func textColor(with color: UIColor) -> Self {
label.textColor = color
return self
}
func numberOf(lines: Int) -> Self {
label.numberOfLines = lines
return self
}
func build() -> UILabel {
return label
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment