refactored more fonts
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
50bb76d806
commit
4c38676f59
@ -119,10 +119,10 @@ open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerable, Initable
|
||||
textAlignment = viewModel.textPosition.textAlignment
|
||||
textColor = textColorHelper.getColor(viewModel)
|
||||
|
||||
if let vdsFont = try? FontStyle.font(for: viewModel.fontCategory, fontWeight: viewModel.fontWeight, fontSize: viewModel.fontSize) {
|
||||
if let vdsFont = self.font {
|
||||
font = vdsFont
|
||||
} else {
|
||||
font = FontStyle.RegularBodyLarge.font
|
||||
font = FontStyle.defaultStyle.font
|
||||
}
|
||||
|
||||
if let attributes = viewModel.attributes, let text = model.text, let font = font, let textColor = textColor {
|
||||
|
||||
@ -42,6 +42,19 @@ public enum FontCategory: String, Codable, CaseIterable {
|
||||
case body
|
||||
case micro
|
||||
|
||||
var fontSizes: [FontSize] {
|
||||
switch self {
|
||||
case .feature:
|
||||
return [.xlarge, .medium, .small, .xsmall]
|
||||
case .title:
|
||||
return [.xxlarge, .xlarge, .large, .medium, .small]
|
||||
case .body:
|
||||
return [.large, .medium, .small, .xsmall]
|
||||
case .micro:
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
var titleCase: String {
|
||||
switch self {
|
||||
case .feature: return "Feature"
|
||||
@ -74,7 +87,7 @@ public enum FontSize: String, Codable, CaseIterable {
|
||||
|
||||
public enum FontStyle: String, Codable, CaseIterable {
|
||||
public enum Error: Swift.Error {
|
||||
case fontNotFound
|
||||
case styleNotFound(fontCatergory: FontCategory, fontSize: FontSize, availableFontSizes: [FontSize])
|
||||
}
|
||||
|
||||
case RegularFeatureXLarge
|
||||
@ -105,6 +118,7 @@ public enum FontStyle: String, Codable, CaseIterable {
|
||||
case BoldBodyMedium
|
||||
case RegularBodySmall
|
||||
case BoldBodySmall
|
||||
|
||||
case RegularMicro
|
||||
case BoldMicro
|
||||
|
||||
@ -181,6 +195,10 @@ public enum FontStyle: String, Codable, CaseIterable {
|
||||
}
|
||||
}
|
||||
|
||||
public static var defaultStyle: FontStyle {
|
||||
return FontStyle.RegularBodyLarge
|
||||
}
|
||||
|
||||
public var font: UIFont {
|
||||
return fontFace.font(ofSize: pointSize)
|
||||
}
|
||||
@ -189,11 +207,15 @@ public enum FontStyle: String, Codable, CaseIterable {
|
||||
return fontFace.font(ofSize: pointSize / 2)
|
||||
}
|
||||
|
||||
public static func font(for category: FontCategory, fontWeight: FontWeight, fontSize: FontSize, isSuperScript: Bool = false) throws -> UIFont {
|
||||
public static func style(for category: FontCategory, fontWeight: FontWeight, fontSize: FontSize) throws -> FontStyle {
|
||||
let fontName = "\(fontWeight.titleCase)\(category.titleCase)\(fontSize.titleCase)"
|
||||
guard let fontStyle = FontStyle(rawValue: fontName) else {
|
||||
throw FontStyle.Error.fontNotFound
|
||||
throw FontStyle.Error.styleNotFound(fontCatergory: category, fontSize: fontSize, availableFontSizes: category.fontSizes)
|
||||
}
|
||||
return fontStyle.font
|
||||
return fontStyle
|
||||
}
|
||||
|
||||
public static func font(for category: FontCategory, fontWeight: FontWeight, fontSize: FontSize) throws -> UIFont {
|
||||
return try style(for: category, fontWeight: fontWeight, fontSize: fontSize).font
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,9 +6,21 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public protocol Fontable {
|
||||
var fontSize: FontSize { get set }
|
||||
var fontWeight: FontWeight { get set }
|
||||
var fontCategory: FontCategory { get set }
|
||||
}
|
||||
|
||||
extension Fontable {
|
||||
|
||||
var style: FontStyle? {
|
||||
return try? FontStyle.style(for: fontCategory, fontWeight: fontWeight, fontSize: fontSize)
|
||||
}
|
||||
|
||||
var font: UIFont? {
|
||||
return self.style?.font
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user