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

时间:2016-07-11 21:35:11

标签: ios xcode ios-simulator ui-testing fastlane-snapshot

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.

5 个答案:

答案 0 :(得分:10)

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()

答案 1 :(得分:8)

从Xcode 8开始,有一个比未记录的启动参数更好的选项:Accessibility Inspector。它包含在this talk中,可以在Xcode>下找到。打开开发人员工具。

Xcode Accessibility Inspector

答案 2 :(得分:2)

在Accessibility Inspector中执行此操作之前,请不要忘记在模拟设备的设置中打开“较大文本”:“常规”->“辅助功能”->“较大字体”。否则,辅助功能检查器将不会显示动态字体选项。

enter image description here

答案 3 :(得分:0)

从iOS 10开始,可以使用UITraitCollection API动态更改动态类型选择。有关详细信息,请参阅https://stackoverflow.com/a/43983241/1148702

答案 4 :(得分:0)

实际上可以在应用程序级别覆盖内容类别的大小,这对于单元和UI测试特别有用。

在此处查看:https://medium.com/livefront/practical-dynamic-type-part-2-testing-613bb845f26b