Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add drop shadow in uicollectionview using swift?

Tags:

swift

I want to add drop shadow in uicollectionview. CollectionView is just covering half of screen, So want to add drop shadow on bottom.

like image 348
Shrestha Ashesh Avatar asked Aug 15 '15 06:08

Shrestha Ashesh


People also ask

How to use uicollectionview in Swift?

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.

How do I add a shadow to a view in Java?

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

What is a shadowpath in UIKit?

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.


1 Answers

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.

like image 136
Developeder Avatar answered Oct 28 '22 02:10

Developeder