What this thread does
Our recommendation: preview your SwiftUI screen with legibilityWeight set to .bold, and read the inherited value when selecting custom font weights. [Jordan Morgan][jordan] [Apple value docs][weight] [Apple modifier docs][environment] [Josh Pensky][josh]
Do first: Our recommendation: add .environment(\.legibilityWeight, .bold) to a preview of the screen you need to inspect. [Apple][environment] [Morgan][jordan]
Compare the two states
Scope: SwiftUI views in iOS apps, using Apple's writable EnvironmentValues.legibilityWeight property. Apple defines it as reflecting the Accessibility Bold Text setting; Pensky (2022-07-19) uses that same value to select a custom font. [Apple][weight] [Pensky][josh]
Our recommendation: keep the override in the preview and compare it with the normal screen. Adapted from Morgan's 2020-01-08 preview injection example using Apple's modifier, which sets an environment value for a view and its descendants. [Apple][environment] [Morgan][jordan]
struct CheckoutView_Previews: PreviewProvider {
static var previews: some View {
Group {
CheckoutView()
.previewDisplayName("Inherited setting")
CheckoutView()
.environment(\.legibilityWeight, .bold)
.previewDisplayName("Bold Text")
}
}
}
Our recommendation: compare text weight and available layout space in these two states before accepting the screen, and check the device's Bold Text preference separately. [Apple][environment] [Morgan][jordan]
Make custom fonts follow the preference
Our recommendation: select your custom font using the inherited legibilityWeight. Pensky (2022-07-19) demonstrates a regular/bold font pair; Apple documents the environment weight and the named-font constructor used below. Adapt the pair to the actual faces in your app. [Pensky][josh] [Apple weight docs][weight] [Apple font docs][font]
struct BrandBody: View {
@Environment(\.legibilityWeight) private var weight
var body: some View {
Text("Order details")
.font(.custom(
weight == .bold ? "Brand-Bold" : "Brand-Regular",
size: 17
))
}
}
Brand-Bold and Brand-Regular are placeholders for your font names. Adapted from Pensky’s 2022-07-19 font-pair selection using Apple’s Font.custom(_:size:). [Pensky][josh] [Apple font docs][font]
Our recommendation: do not solve a visual mismatch by forcing .regular on the production hierarchy. Read the user's preference there, and reserve the forced value for comparison. This recommendation adapts Apple's environment modifier and Pensky's 2022-07-19 inherited-value example. [Apple][environment] [Pensky][josh]
Limits
This recipe checks the SwiftUI font-selection and preview path; it does not provide an XCUITest command for changing the system Bold Text preference or claim that an accessibility audit certifies Bold Text support. The custom-font adaptation depends on the faces your app actually supplies.
Sources and dates
Pensky's 2022-07-19 article is one author's implementation example, not a report covering every typeface.
Sources and dates: Jordan Morgan, Xcode Preview Snips, 2020-01-08; Josh Pensky, Supporting Bold Text with Custom Fonts in SwiftUI, 2022-07-19; Apple's legibilityWeight, environment(_:_:) and Font.custom(_:size:) references, undated docs.
[jordan]: https://www.swiftjectivec.com/xcode-preview-snips/ [josh]: https://dev.to/joshpensky/supporting-bold-text-with-custom-fonts-in-swiftui-2kgg [weight]: https://developer.apple.com/documentation/swiftui/environmentvalues/legibilityweight [environment]: https://developer.apple.com/documentation/swiftui/view/environment(_:_:) [font]: https://developer.apple.com/documentation/swiftui/font/custom(_:size:)
Started from a post by @Jordan Morgan, packaged by the editor. Original post