F.SO4 F.SO4 - 5 months ago 26
iOS Question

Adding shadow to floating UICollectionView headers

I have an

UICollectionView
with 2 sections, each one has its own floating header.

My question is if is there any way to add shadow below the header that will be displayed on the collection's cells?

Answer

Make a pointer to your collection view's header. (Info)

Then apply following CALayer? effect:

Objective-c

    yourObject.clipsToBounds = NO;//necessary, dont change
    yourObject.layer.masksToBounds = NO;//necessary, dont change
    yourObject.layer.shadowColor = [[UIColor blackColor] CGColor];//color
    yourObject.layer.shadowOpacity = 0.5f;//translucency (alpha)
    yourObject.layer.shadowRadius = 1.5f;//size | spread
    yourObject.layer.shadowOffset = CGSizeMake(0.0f, 2.5f);//direction (x,y)

Convert to Swift as needed.