Last active
May 10, 2018 19:44
-
-
Save bolivarbryan/36dbafd7208ae25543a70912e10513f9 to your computer and use it in GitHub Desktop.
UILabel component, ready to use
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
import UIKit | |
class BBLabel: UILabel { | |
enum FontSize: CGFloat { | |
case small = 12.0 | |
case medium = 14.0 | |
case large = 30.0 | |
} | |
enum FontWeight: String { | |
case regular = "" | |
case bold = "-Bold" | |
} | |
enum FontFamily: String { | |
case system = "Helvetica" | |
func getFontName(weight: FontWeight) -> String { | |
return "\(self.rawValue)\(weight.rawValue)" | |
} | |
} | |
init(text: String, | |
color: UIColor, size: FontSize = .small, | |
weight: FontWeight = .regular, | |
family: FontFamily = .system) { | |
super.init(frame: CGRect.zero) | |
self.text = text | |
textColor = color | |
self.font = UIFont(name: family.getFontName(weight: weight), size: size.rawValue) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment