This file contains hidden or 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
    
  
  
    
  | class WeightAdheringLabel: UILabel { | |
| private var originalFont: UIFont? | |
| override var font: UIFont! { | |
| set { | |
| self.originalFont = newValue | |
| if traitCollection.legibilityWeight == .bold { | |
| super.font = newValue.fontDescriptor.withSymbolicTraits(.traitBold).map { UIFont(descriptor: $0, size: newValue.pointSize) } ?? newValue | |
| } else { | |
| super.font = newValue | 
  
    
      This file contains hidden or 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
    
  
  
    
  | let font = UIFont(name: "Cochin", size: 16)! | |
| let scaledFont = UIFontMetrics(forTextStyle: .body).scaledFont(for: font) | |
| label.font = scaledFont | |
| label.adjustsFontForContentSizeCategory = true | 
  
    
      This file contains hidden or 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
    
  
  
    
  | override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { | |
| stack.axis = traitCollection.preferredContentSizeCategory > .extraExtraExtraLarge ? .vertical : .horizontal | |
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
  | stackView.axis = traitCollection.preferredContentSizeCategory > .extraExtraExtraLarge ? .vertical : .horizontal | 
  
    
      This file contains hidden or 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
    
  
  
    
  | let label = UILabel() | |
| label.font = UIFont.preferredFont(forTextStyle: .caption1) | |
| label.adjustsFontForContentSizeCategory = true | 
  
    
      This file contains hidden or 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
    
  
  
    
  | timeLabel.font = FontStyles.bigTime | |
| timeLabel.adjustsFontForContentSizeCategory = false | 
  
    
      This file contains hidden or 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
    
  
  
    
  | struct FontStyles { | |
| private static let customFont = UIFont(name: "Cochin", size: 15)! | |
| static let headline = customFont.with(style: .headline, basePointSize: 34) | |
| static let body = customFont.with(style: .body, basePointSize: UIFont.labelFontSize) | |
| static let bigTime = customFont.withSize(66) | |
| static let buttonPrimary = customFont.with(style: .body, basePointSize: UIFont.buttonFontSize) | |
| static let buttonSecondary = customFont.with(style: .caption1, basePointSize: UIFont.smallSystemFontSize) | |
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
  | extension UIFont { | |
| func with(style: UIFont.TextStyle, basePointSize: CGFloat, maxPointSize: CGFloat? = nil) -> UIFont { | |
| if let maxPointSize = maxPointSize { | |
| return UIFontMetrics(forTextStyle: style).scaledFont(for: self.withSize(basePointSize), | |
| maximumPointSize: maxPointSize) | |
| } | |
| return UIFontMetrics(forTextStyle: style).scaledFont(for: self.withSize(basePointSize)) | |
| } | |
| } |