README and documentationIGListKit version: 3.0.0Hi,
I have a cell (CityCell) showing an image and a label.
The first cell must have a length equal to the view, while the other cells must have half the length of the view.
So in the first row I have one item, in the other rows I have two items per row.
So I have this:
override func sizeForItem(at index: Int) -> CGSize {
let width = collectionContext!.containerSize.width
if index == 0 {
return CGSize(width: width, height: width/2)
} else {
return CGSize(width: width/2, height: width/2)
}
}
The problem is that the items have wrong size, and each time I scroll the view they assume different sizes.
I created a demo project with this problem: link
and you can also see a video: link
I am currently solving this problem by creating another ViewCell that I use only for the first element. In cellForItem, if index == 0 I cast the first item to the new ViewCell otherwise to CityCell
Thanks... and a big thank you for this awesome framework
Your code in your repo is empty. Could you submit the code?
oops :)
I have submitted the code.
Hey, thanks for providing a demo project, that makes it easier to help :)
The problem seems to be that you are hard coding the frames of the labels

It won't help what frame you set as the superview, when the image and the label has hard coded sizes.
I would propose you watch some of the great WWDC videos about AutoLayout. It will help you a lot with understanding how the layout engine of UIKit works.
To fix your problem I added an extension to UIView that will fill the view with the subview.


You can grab it here if you want to re-use it:
extension UIView {
func fillWith(_ view: UIView, usingConstraints: Bool = true) {
addSubview(view)
if usingConstraints {
view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
topAnchor.constraint(equalTo: view.topAnchor),
leftAnchor.constraint(equalTo: view.leftAnchor),
rightAnchor.constraint(equalTo: view.rightAnchor),
bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
} else {
view.frame = bounds
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}
}
}
I think we can consider this issue soved :)
@heumn slay!
Totally forgot to look into this. My apologies 馃槥
Hi @heumn
thanks for the information and for the fix! :)
My pleasure :) Best of luck!
Most helpful comment
Hey, thanks for providing a demo project, that makes it easier to help :)
The problem seems to be that you are hard coding the frames of the labels
It won't help what frame you set as the superview, when the image and the label has hard coded sizes.
I would propose you watch some of the great WWDC videos about AutoLayout. It will help you a lot with understanding how the layout engine of UIKit works.
To fix your problem I added an extension to UIView that will fill the view with the subview.
You can grab it here if you want to re-use it:
I think we can consider this issue soved :)