I can't get my UICollection to properly set sectionInset.left
margin when using self-sizing cells with estimatedItemSize
. Cells of the UICollectionview should have a somewhat fixed cell height but dynamic width according to the text length.
Here is how it looks when the self-sizing is enabled:
And when the self-sizing is disabled:
Oddly enough, it seems that sectionInset.right
is working, i.e. the margin is added on the right hand side of the UICollectionView.
Here's my custom UICollectionViewFlowLayout, i'm toggling self-size mode using the comment.
class myFlow: UICollectionViewFlowLayout {
required init(coder: NSCoder) {
super.init(coder: coder)
self.minimumLineSpacing = 1
// self.estimatedItemSize = CGSize(width: 100, height: 35)
self.sectionInset.left = 20
}
And my custom UICollectionView:
class myCV: UICollectionView {
required init(coder decoder: NSCoder) {
super.init(coder: decoder)
self.layer.cornerRadius = 5.0
self.layer.borderWidth = 1.0
self.layer.borderColor = UIColor.lightGrayColor().CGColor
}
}
I've laid out the label inside the UICollectionView cell using AutoLayout:
I've found a work around this - use
contentInset
property ofUIScrollView
, that is super class ofUICollectionView
. It is not strictly saying is answer, but, at least, a solution of the problem