How to test Dynamic Type (larger font sizes) in iOS Simulator
Asked Answered
A

5

12

Changing Dynamic Type settings in iOS can be done manually (Settings > General > Accessibility > Larger Text).

But this does not appear to work in the current Simulator (v9.3 at the time of writing), and doing so manually is not a solution where automation is required.

Question: Is there a way to launch an app with Dynamic Type settings to launch an app with larger font sizes?

Note: This is not only useful for UI testing, but also for the purpose of creating screenshots using Fastlane Snapshot with larger font sizes.

Anesthesia answered 11/7, 2016 at 21:35 Comment(0)
S
11

As of Xcode 8, there is a better option than the undocumented launch arguments: Accessibility Inspector. It is covered in this talk and can be found under Xcode > Open Developer Tool.

Update for Xcode 11+

There is a new Environment Overrides option. Find more information in this answer.

Xcode Accessibility Inspector

Salbu answered 21/6, 2017 at 3:31 Comment(4)
Nice Xcode improvement! Thank you -- I've changed the accepted answer to this one as it is now the best approach. But for people looking to do this for Fastlane screenshots, please see that other answer!Anesthesia
Xcode 10 seems to have dropped the "Font size" option. The only options are (1) Invert colors, (2) Increase contrast, (3) Reduce transparency, (4) Reduce motion, and (5) Full keyboard access. Anyone know if the "Font size" option has been moved somewhere else?Smirk
If you still can't see it make sure to enable ´Large Accessibility Size´ in settings and that you select the correct simulator in the top left dropdown in the accessibility inspector. Don't select My mac --> Simulator there should be simulator below the Mac in the dropdown.Demimondaine
The Accessibility Inspector tool has changed in Xcode 11 that has introduced a new option inside the LOG window: see this answer https://mcmap.net/q/670417/-is-there-a-faster-way-to-change-accessibility-dynamic-type-text-size-on-ios-simulator for further details.Unsheathe
A
20

Although (to my knowledge) not documented, a launch argument can be used to define the initial Dynamic Type setting.

Key: UIPreferredContentSizeCategoryName

Value: One of the below

  • UICTContentSizeCategoryXS
  • UICTContentSizeCategoryS
  • UICTContentSizeCategoryM
  • UICTContentSizeCategoryL
  • UICTContentSizeCategoryXL
  • UICTContentSizeCategoryXXL
  • UICTContentSizeCategoryXXXL
  • UICTContentSizeCategoryAccessibilityM
  • UICTContentSizeCategoryAccessibilityL
  • UICTContentSizeCategoryAccessibilityXL
  • UICTContentSizeCategoryAccessibilityXXL
  • UICTContentSizeCategoryAccessibilityXXXL

Source of this undocumented key/values: GitHub.

A convenient way to do so is to add a launch argument to an Xcode scheme (add for example -UIPreferredContentSizeCategoryName UICTContentSizeCategoryXL under Arguments Passed On Launch), and this setting will apply when you run the app in Xcode. You can create multiple schemes with different Dynamic Type settings to switch between them.

If the purpose is creating screenshots using Fastlane Snapshot, the equivalent code is as follows:

app.launchArguments += [ "-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryXL" ]
app.launch()
Anesthesia answered 11/7, 2016 at 21:35 Comment(0)
S
11

As of Xcode 8, there is a better option than the undocumented launch arguments: Accessibility Inspector. It is covered in this talk and can be found under Xcode > Open Developer Tool.

Update for Xcode 11+

There is a new Environment Overrides option. Find more information in this answer.

Xcode Accessibility Inspector

Salbu answered 21/6, 2017 at 3:31 Comment(4)
Nice Xcode improvement! Thank you -- I've changed the accepted answer to this one as it is now the best approach. But for people looking to do this for Fastlane screenshots, please see that other answer!Anesthesia
Xcode 10 seems to have dropped the "Font size" option. The only options are (1) Invert colors, (2) Increase contrast, (3) Reduce transparency, (4) Reduce motion, and (5) Full keyboard access. Anyone know if the "Font size" option has been moved somewhere else?Smirk
If you still can't see it make sure to enable ´Large Accessibility Size´ in settings and that you select the correct simulator in the top left dropdown in the accessibility inspector. Don't select My mac --> Simulator there should be simulator below the Mac in the dropdown.Demimondaine
The Accessibility Inspector tool has changed in Xcode 11 that has introduced a new option inside the LOG window: see this answer https://mcmap.net/q/670417/-is-there-a-faster-way-to-change-accessibility-dynamic-type-text-size-on-ios-simulator for further details.Unsheathe
T
2

Before doing this in Accessibility Inspector, don't forget to turn on "Larger Text" in your simulated device's settings: General -> Accessibility -> Larger Font. Else, the Accessibility Inspector won't show the dynamic font option.

enter image description here

Teel answered 20/6, 2018 at 11:40 Comment(0)
T
1

As of iOS 10, it is possible to dynamically alter the dynamic type choice using the UITraitCollection API. See https://mcmap.net/q/670418/-dynamically-mocking-ios-dynamic-type-system-text-size-uicontentsizecategory for more info.

Topotype answered 22/5, 2017 at 16:4 Comment(0)
B
1

It is actually possible to overwrite the content category size at the application-level which is especially useful for unit and UI tests.

Check it out here: https://medium.com/livefront/practical-dynamic-type-part-2-testing-613bb845f26b

Bisector answered 13/12, 2018 at 0:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.