Repository navigation
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 factorUIFontMetricsapplies on iOS and a system font by the ratio of the iOS preferred font sizes, both rounded to whole points as on iOS..largereturns 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 thedynamicTypeSizeof the environment. TextSizePreferencestores 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 anObservableObject, AppKit throughdidChangeNotification.
See #6 and the new article Offering an In-App Text Size in the documentation.
Examples
TextSizeDemo, a macOS app in theExamplesfolder that changes the text size from the View menu, the toolbar and Settings, for text in SwiftUI and in AppKit. Run it withswift run TextSizeDemoin 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 thescaledFont(_:)modifiers.
Full changelog: 1.1.1...1.2.0