UIStackView creates incorrect constraints for a "fillProportional" distribution and a non-zero spacing

Originator:mischamail
Number:rdar://34595752 Date Originated:22 September 2017
Status:Open Resolved:No
Product:iOS + SDK Product Version:10.3
Classification:Bug Reproducible:Always
 
Summary:
According to the Apple documentation, a stack view with a "fillProportionally" distribution should layout its arranged subviews in a way that are scaled proportionally based on their intrinsic content size along the stack view axis so that they just fill the stack view.

If the stack view's spacing is set to any value other than 0, this is not the case.
The layout always breaks if spacing > 0.

I have analyzed the problem and discovered that the multipliers of the "UISV-fill-proportionally" constraints are incorrect. A more detailed explanation and the correct formula for the multiplier can be found on Stackoverflow:
https://stackoverflow.com/a/46368061/2062785

Steps to Reproduce:
1. Create a stack view with fixed width and a horizontal axis. Set its distribution to "fillProportional" and its spacing to a value greater than 0.
2. Create a custom UIView subclass and override its intrinsicContentSize to return a size with a fixed width.
3. Add several instances of this subclass as arranged subviews to the stack view and set their background color to a value so that you can distinguish them from the background.
4. Observe the resulting layout.
Please check the attached project. All the steps above are implemented in there, ready to be tested.

Expected Results:
As all views have the same intrinsic width they should all have the same width and share the available space (= stack view width – total spacing width).

Actual Results:
Depending on the particular spacing, the layout is different. For small spacings all arranged subviews have the same width except for the last one which is stretched to fill the remaining space. For bigger spacings the layout is different but still not as expected.

Version/Build:
iOS 10.3

Configuration:

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!