Inconsistent Results when assigning variable width string to label

Originator:eric.s.blair
Number:rdar://39149993 Date Originated:03-Apr-2018 03:23 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 11.3 (15E216)
Classification:Security Reproducible:Always
 
Summary:
When using a localized string with variants, I’ve seen iOS pick different length-based representations of the string at times you’d expect it to pick the same representation.

Steps to Reproduce:
1. Create a stringsdict file and a string key. Configure the string with a NSStringVariableWidthRuleType dictionary and define values for the 20 and 25 width keys.
2. Add a label to your view controller and connect that label to an outlet
3. In the view controller implementation, override traitCollectionDidChange(_:) and set the label’s text to a localized string from step 1.
4. On an iPhone 5S or SE (or for an iPhone only app, an iPad), launch the app in landscape mode. Note the value of the string.
5. Rotate to portrait mode
6. Rotate back to landscape mode

Expected Results:
The value of the label in step 4 and 6 should be identical.

Actual Results:
When the app launches in landscape mode, the 25 width representation is displayed in the UI.
When the app rotates to portrait, the 20 width representation is displayed.
When the app rotates back to landscape mode, the 20 width representation continues to be used instead of matching the app when it’s initially launched in landscape mode

Version:
iOS 11.3 (15E216)

Notes:
I’m not sure if the issue lies in the calculate at launch time or at rotation time.

This is the combination of numbers that works on a screen that’s 568x320. There might be other values that work for other devices and configurations.

The attached project demonstrates the issue.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!