Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView Cell Shadow

I am trying to add shadow to my custom UICollectionViewCell, This is the code I am using in my custom collection view cell class:

self.layer.shadowOffset = CGSizeMake(1, 0);
self.layer.shadowColor = [[UIColor blackColor] CGColor];
self.layer.shadowRadius = 5;
self.layer.shadowOpacity = .25;

This is giving shadow to the components of the collection view cell.

like image 528
Avinash Sharma Avatar asked Jan 05 '17 14:01

Avinash Sharma


People also ask

How do you add a shadow to a table in a cell?

One alternative approach you can try, take a UIView in UITableViewCell . Set background color of UITableViewCell to clear color. Now, you can make round corners and add shadow on UIVIew . This will appear as if cell width is reduced and user can scroll along the edges of the tableView.

How to add corner radius for Collection view cell?

Rounded Corners on a UICollectionViewCell To apply rounded corners, set a cornerRadius on both the layer and contentView. layer properties. On the contentView. layer , set masksToBounds to true so the contentView contents are clipped to the rounded corners.

What is swift Uicollectionview?

An object that manages an ordered collection of data items and presents them using customizable layouts.


1 Answers

Don't forget to add these 2 lines

self.clipsToBounds = false      
self.layer.masksToBounds = false
like image 54
Vinu David Jose Avatar answered Oct 14 '22 07:10

Vinu David Jose