Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
86 views
in Technique[技术] by (71.8m points)

ios - How can I center rows in UICollectionView?

I have a UICollectionView with random cells. Is there any method that allows me to center rows?

This is how it looks by default:

[ x x x x x x ]  
[ x x x x x x ]  
[ x x         ]  

Here is what the desired layout looks like:

[ x x x x x ]  
[ x x x x x ]  
[    x x    ]  
question from:https://stackoverflow.com/questions/16544186/how-can-i-center-rows-in-uicollectionview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had to do something like this, but needed all the cells in the one section. It was pretty simple to extend UICollectionViewFlowLayout to center cells. I made a pod:

https://github.com/keighl/KTCenterFlowLayout

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...