Skip to content

1.2.0

Latest

Choose a tag to compare

@gewill gewill released this 19 Sep 05:00
0823df9

Adds an in-app text size for macOS, where there is no Dynamic Type. Apps that do not choose a text size get the same fonts as with 1.1.1.

In-App Text Size

  • font(forTextStyle:design:weight:dynamicTypeSize:) returns a font scaled for a Dynamic Type size that the app chooses. On macOS, a custom font scales by the factor UIFontMetrics applies on iOS and a system font by the ratio of the iOS preferred font sizes, both rounded to whole points as on iOS. .large returns the same font as before, and a larger size never gets a smaller font, even with a fractional style dictionary size (#11).
  • On iOS, iPadOS, tvOS and visionOS, the same method takes an explicit size that replaces the size chosen in the system settings.
  • On macOS 12 and later, the scaledFont(_:) modifiers scale their fonts for the dynamicTypeSize of the environment.
  • TextSizePreference stores the size in the user defaults of the app, keeps it within a range that includes every accessibility size by default, and posts a notification when it changes. SwiftUI observes it as an ObservableObject, AppKit through didChangeNotification.

See #6 and the new article Offering an In-App Text Size in the documentation.

Examples

  • TextSizeDemo, a macOS app in the Examples folder that changes the text size from the View menu, the toolbar and Settings, for text in SwiftUI and in AppKit. Run it with swift run TextSizeDemo in that folder.
  • Examples/SystemFonts.plist, a style dictionary that uses the system font with the serif and monospaced designs and a bold weight.

Documentation

  • README sections on what this fork adds, on macOS support, on using ScaledFont with AppKit and on the in-app text size.
  • The Swift Package Index builds the documentation on macOS, so it includes the AppKit API, and the README badges show this fork.

Upgrading

  • On macOS 12 and later, a view hierarchy that already sets dynamicTypeSize, for example in code shared with iOS, now gets scaled fonts from the scaledFont(_:) modifiers.

Full changelog: 1.1.1...1.2.0