Customize layout of UICollectionViewFlowLayout's last row.
| Originator: | steipete | ||
| Number: | rdar://20825965 | Date Originated: | 05-May-2015 05:51 PM |
| Status: | Open | Resolved: | |
| Product: | iOS | Product Version: | 8.3 |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
UICollectionViewFlowLayout's last row is left-aligned by default if items have a non-uniform height, when many use cases would expect a justified positioning. This can be customized using private API, but is not public.
Steps to Reproduce:
Open example. Observe this: http://cl.ly/image/0F3f2P453X2W
Expected/Wanted: http://cl.ly/image/2K330W304021
Expected Results:
Last line layout should be justified.
Actual Results:
Last line layout is not justified.
Regression:
This is the case since iOS 6.
Notes:
I discovered this back then when I wrote PSTCollectionView. A horrible, private API workaround is this:
NSMutableDictionary *rowAlignmentOptions = [NSMutableDictionary dictionaryWithDictionary:[flowLayout valueForKey:@"rowAlignmentOptions"]];
rowAlignmentOptions[@"UIFlowLayoutLastRowHorizontalAlignmentKey"] = rowAlignmentOptions[@"UIFlowLayoutCommonRowHorizontalAlignmentKey"];
flowLayout setValue:rowAlignmentOptions forKey:@"rowAlignmentsOptions"];
It’s unexpected that lay-outing changes as soon as one size has a non-uniform height, which I assume has to do with an internal optimization that calculates the frames faster for uniform-sized elements.
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!
Example: http://cl.ly/212d090r3x0J