Skip to content

Instantly share code, notes, and snippets.

@bolivarbryan
Last active May 10, 2018 19:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bolivarbryan/36dbafd7208ae25543a70912e10513f9 to your computer and use it in GitHub Desktop.
Save bolivarbryan/36dbafd7208ae25543a70912e10513f9 to your computer and use it in GitHub Desktop.
UILabel component, ready to use
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