Recently, I tried to use a UICollectionViewController to show some buttons, I thought it shouldn't be difficult, for I heard lots of people said it's very similar to UITableViewController, and one thing let me struggling a little long.
A good way to show buttons in a nice layout. It turns out the UICollectionViewController's layout has some default values for some properties.
let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
layout.sectionInset = UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2)
layout.itemSize = CGSizeMake((self.view.frame.width-8)/3,(self.view.frame.width-8)/3)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 2
if you don't want any margin for your cell, you need to override below two properties, for the default value is 10.
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
No comments:
Post a Comment