给UICollectionViewCell设置圆角和阴影

效果图:

给UICollectionViewCell设置圆角和阴影_第1张图片

实现代码:

self.contentView.layer.cornerRadius = 9;
self.contentView.backgroundColor = [UIColor whiteColor];
self.contentView.layer.masksToBounds =YES;

self.layer.shadowColor = [UIColor lightGrayColor].CGColor;// 阴影颜色
self.layer.shadowOffset = CGSizeMake(0, 2);// 阴影偏移
self.layer.shadowRadius = 2;// 阴影半径
self.layer.shadowOpacity = 0.8;// 阴影透明度,默认为0
self.layer.masksToBounds = NO;
self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.contentView.layer.cornerRadius].CGPath;

 

你可能感兴趣的:(给UICollectionViewCell设置圆角和阴影)