added helper for scaledFonts

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-07-21 10:43:55 -05:00
parent 61e843f8f8
commit 02150f8e8c

View File

@ -39,13 +39,16 @@ extension FontProtocol {
throw error!.takeUnretainedValue()
}
}
public func font(ofSize size: CGFloat) -> UIFont{
public func font(ofSize size: CGFloat, isScaled: Bool = true) -> UIFont{
DispatchQueue.once(block: { self.register() })
if let font = UIFont(name: self.fontName, size: size){
return UIFontMetrics.default.scaledFont(for: font)
} else {
return UIFontMetrics.default.scaledFont(for: UIFont.systemFont(ofSize: size))
}
guard let found = UIFont(name: self.fontName, size: size) else { return .systemFont(ofSize: size) }
return found
}
}
extension UIFont {
public var scaledFont: UIFont {
UIFontMetrics.default.scaledFont(for: self)
}
}