UIFont.swift 534 B

123456789101112131415161718192021222324
  1. //
  2. // UIFont.swift
  3. // Mastodon
  4. //
  5. // Created by BradGao on 2021/2/20.
  6. //
  7. import UIKit
  8. extension UIFont {
  9. private func withTraits(traits: UIFontDescriptor.SymbolicTraits) -> UIFont {
  10. let descriptor = fontDescriptor.withSymbolicTraits(traits)
  11. return UIFont(descriptor: descriptor!, size: 0) //size 0 means keep the size as it is
  12. }
  13. func bold() -> UIFont {
  14. return withTraits(traits: .traitBold)
  15. }
  16. func italic() -> UIFont {
  17. return withTraits(traits: .traitItalic)
  18. }
  19. }