Day 146

Ship bolder fonts when Bold Text is on

11 Oct 2022

If the user has Bold Text enabled, it will just work if you are using fonts based on text styles. If you have your own styles, or you are using a non-system font, you'll need to provide the bolder version of the font when the setting is on.

Some code shows how a single line is all you need for it to work with both Dynamic Type and Bold Text if you use preferred fonts for one of the pre-defined text styles. If you try to load a custom font, like Comic Sans, you then need to check if isBoldTextEnabled is true, and in that case, you need to load the bold version of the font. You can then retrieve the scaled font from UIFontMetrics, to have a similar behaviour to the system font, with the custom font.

Some of you have asked me how you can support what I do. This would really help, and would be hugely appreciated:

  • Find these posts useful? Share them at work, on social media, or with anyone that might find them interesting. Let's spread the word!

  • Check out any of my apps or games: Xarra!, RetroRapid!, or Mestre!.

    • A download and a review go a long way. They're free by default. On the App Store, ratings and reviews really help more people discover them.

    • Finding any of them useful? If so, and if you can afford it, purchasing lifetime access to all features or subscribing lets me buy the coffee that keeps me caffeinated. Caffeine keeps me going to maintain the apps, bring in new features that I hope you'll love, and keep writing.

You may also find interesting...

Your iconography should support Bold Text too. One way of doing it is by creating custom symbols (and specifying weights for it) to work with them as you would with regular SF Symbols. How Creating custom symbols: https://developer.apple.com/videos/play/wwdc2021/10250/

In iOS' Settings you can specify your preference to use bold text. This can be checked in code in a couple ways: 1. isBoldTextEnabled in UIAccessibility: https://developer.apple.com/documentation/uikit/uiaccessibility/isboldtextenabled 2. legibilityWeight from UITraitCollection: https://developer.apple.com/documentation/uikit/uitraitcollection/legibilityweight

If you are displaying something in two or more columns, you may want to change that to as little as one column when using some of the largest Dynamic Type settings to keep the text readable.


Content © Daniel Devesa Derksen-Staats on Accessibility up to 11! is licensed under CC BY 4.0. License details