I would like to understand why setting clipsToBounds/masksToBounds to False have no impact on UICollectionViewCell subviews (in my case its UILabel).
I tried any possible solution with clipsToBounds/masksToBounds (although I think under the hood they behave/do the same).
override open func layoutSubviews() {
super.layoutSubviews()
super.clipsToBounds = false
super.layer.masksToBounds = false
self.clipsToBounds = false
self.layer.masksToBounds = false
self.contentView.clipsToBounds = false
self.contentView.layer.masksToBounds = false
self.contentView.superview?.clipsToBounds = false
self.contentView.superview?.layer.masksToBounds = false
self.endTime.layer.masksToBounds = false
self.endTime.clipsToBounds = false
self.endTime.layer.zPosition = CGFloat(FLT_MAX)
}
I do override UICollectionViewLayout according to Custom layout from raywenderlich
override public func prepare() {
if cache.isEmpty {
let columnWidth = contentWidth / CGFloat(numberOfColumns)
var xOffset = [CGFloat]()
for column in 0 ..< numberOfColumns {
xOffset.append(CGFloat(column) * columnWidth )
}
let column = 0
var yOffset = [CGFloat](repeating: 0, count: numberOfColumns)
for item in 0 ..< collectionView!.numberOfItems(inSection: 0) {
let indexPath = NSIndexPath(row: item, section:0)
let frame = CGRect(x: xOffset[column], y: yOffset[column], width: cellSize.width, height: cellSize.height)
let insetFrame = frame.insetBy(dx: cellPaddingX, dy: cellPaddingY)
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath as IndexPath)
attributes.frame = insetFrame
cache.append(attributes)
contentHeight = max(contentHeight, frame.maxY)
yOffset[column] = yOffset[column] + cellSize.height + minimumLineSpacing
}
}
}
public override var collectionViewContentSize: CGSize {
return CGSize(width: contentWidth, height: contentHeight)
}
override open func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var layoutAttributes = [UICollectionViewLayoutAttributes]()
for attributes in cache {
if attributes.frame.intersects(rect) {
layoutAttributes.append(attributes)
}
}
return layoutAttributes
}
Result:
The red vertical line indicates "Unavailable" its starts from one cell and may finish in another (depends on time duration). From the UI Debug its seems that each next cell always on the top of previous one.(The 21:00 cell is the only one that looks as I want)