Skip to content

Instantly share code, notes, and snippets.

@shadone
Created January 12, 2024 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadone/ad2e179290f62f5564a1227da5d80629 to your computer and use it in GitHub Desktop.
Save shadone/ad2e179290f62f5564a1227da5d80629 to your computer and use it in GitHub Desktop.
private var titleAttributes: AnyPublisher<[NSAttributedString.Key: Any], Never> {
appearance.textSizeAdjustmentPublisher
.combineLatest(isRead)
.map { textSizeAdjustment, isRead -> [NSAttributedString.Key: Any] in
[
.font: UIFont.scaledSystemFont(
style: .title2,
relativeSize: textSizeAdjustment,
weight: .medium
),
.foregroundColor: isRead ? UIColor.secondaryLabel : UIColor.label,
]
}
.eraseToAnyPublisher()
}
extension UIFont {
static func scaledSystemFont(
style textStyle: UIFont.TextStyle,
relativeSize: CGFloat,
weight: UIFont.Weight = .regular
) -> UIFont {
let font = UIFont.systemFont(
ofSize: UIFont.systemFontSize + relativeSize,
weight: weight
)
return UIFontMetrics(forTextStyle: textStyle)
.scaledFont(for: font)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment