Closed thedevme closed 7 years ago
@thedevme The grid layout only supports left alignment at the time. For your use case, I think UICollectionViewFlowLayout
might be more suitable (if you only have one Section Controller per line).
I am not sure what you mean - so are you saying use reg collection view for this? I will need it to be centered.
I mean use UICollectionViewFlowLayout
instead of IGListCollectionViewLayout
.
Ahh ok thank you very much for the quick response
@zhubofei does this also apply to a grid?
I tried using UICollectionViewFlowLayout but it won't show up in a grid - when I use IGListCollectionViewLayout I get the following. But I need the following:
@thedevme No. UICollectionViewFlowLayout newlines section controllers. If you want grid layout and center alignment at the same time. We have to do the math yourself. Setup the right width and spacing.
I have tried with both ways doing it with math and setting the width and it still doesn't thought it might be a bug. Thanks
@thedevme can you use IGListCollectionViewLayout
and set the contentInset
of the collection view itself to something to "center" the content?
Same thing here.. If I am using Flow layout, insets works like a charm.. but when using Grid, settings the insets has no effect. Here is my code:
import UIKit
import IGListKit
class InviteFriendsSectionController: IGListSectionController {
var item: String!
let spacing = CGFloat(20)
override init() {
super.init()
minimumLineSpacing = spacing
minimumInteritemSpacing = spacing
inset = UIEdgeInsets(top: spacing, left: spacing, bottom: spacing, right: spacing)
}
}
extension InviteFriendsSectionController: IGListSectionType {
func numberOfItems() -> Int {
return 1
}
func sizeForItem(at index: Int) -> CGSize {
guard let context = collectionContext else { return .zero }
let width = context.containerSize.width / 2 - spacing * 2
return CGSize(width: width, height: width)
}
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext?.dequeueReusableCellFromStoryboard(withIdentifier: "InviteFriendCell", for: self, at: index) as! InviteFriendCell
cell.imageView.image = UIImage(named: item)
return cell
}
func didUpdate(to object: Any) {
item = object as? String
}
func didSelectItem(at index: Int) {
}
}
Help me please!
@D-Link13 can you try using the master branch and our IGListCollectionViewLayout
layout instead? We've deprecated the grid layout in favor of an upgraded one that better supports insets and inline sections/items.
If you're still having trouble please open a new issue so we can track there!
I have not been able to find a solution for this as all the examples have the grid flowing to the left. I need to get my grid to be centered. Currently it is floating to the left:
I am not sure why my values for inset are not working but they are not in the SectionController. Any advice? Thanks