I want to add drop shadow in uicollectionview. CollectionView is just covering half of screen, So want to add drop shadow on bottom.
How to use UICollectionView in Swift? How to use UICollectionView in Swift? To use collection view in swift, first, we need to create a collection View. We can either drag and drop it to the storyboard, or we can make it programmatically.
To add a shadow to our new view, we need to add the following lines of code to our newView () method just below the view.backgroundColor = .blue: view. layer. shadowOffset = CGSize( width: 10, height: 10) view. layer. shadowRadius = 5 view. layer. shadowOpacity = 0.3
This means that UIKit has needed to calculate the shadows path on the fly. Creating a shadow in this way is a very expensive task, and when depending on the device and the number of views that need shadows, doing this can decrease performance dramatically. To fix this we can use a shadowPath.
This will make a drop shadow at the bottom of the UICollectionView
myCollection.layer.shadowColor = UIColor.blackColor().CGColor
myCollection.layer.shadowOffset = CGSizeMake(0, 1)
myCollection.layer.shadowOpacity = 1
myCollection.layer.shadowRadius = 1.0
myCollection.clipsToBounds = false
myCollection.layer.masksToBounds = false
Note that UICollectionView
is initialized with the following by default:
clipsToBounds = true
layer.masksToBounds = true
and you must set them to false
otherwise the shadow will not be displayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With