UICollectionView Cell Shadow

I am trying to add a shadow to my custom one UICollectionViewCell. This is the code I use in my socket class:

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

This gives shadow to the components of the collection view cell.

+4
source share
3 answers

Remember to add these 2 lines

self.clipsToBounds = false      
self.layer.masksToBounds = false
+6
source

Go to the file CustomCollectionViewCell.m Worked for me. Hope this helps ...

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //////// make shadow  of total view
        self.clipsToBounds = NO;
        self.layer.masksToBounds = NO;
        self.layer.shadowRadius = 5;
        self.layer.shadowOpacity = 0.5;
        self.layer.shadowColor = [UIColor blackColor].CGColor;
        self.layer.shadowOffset = CGSizeMake(0, 1);
        self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;

        // make radius of the cell
        self.layer.cornerRadius = 5;

    }
    return self;
}
0
source

cell.layer.backgroundColor

cell.layer.backgroundColor = UIColor.white.cgColor
0

Source: https://habr.com/ru/post/1665890/


All Articles