简体   繁体   中英

How to add a shadow to the inside bottom edge of a collection view cell? swift 3

I'd like to create a collectionViewCell, I currently have a UIImageView taking up the entire contentView of the cell but would like to add a shadow to the bottom of the image (starting at the bottom edge going towards the middle of the cell). How would I go about doing this in swift 3?

Thanks

Try this:

yourCollectionViewCell.layer.masksToBounds = false
yourCollectionViewCell.layer.borderColor = UIColor.white.cgColor
yourCollectionViewCell.layer.borderWidth = 7.0
yourCollectionViewCell.layer.contentsScale = UIScreen.main.scale
yourCollectionViewCell.layer.shadowOpacity = 0.75
yourCollectionViewCell.layer.shadowRadius = 5.0
yourCollectionViewCell.layer.shadowOffset = CGSize.zero
yourCollectionViewCell.layer.shadowPath = UIBezierPath.init(rect: yourCollectionViewCell.bounds).cgPath
cell.layer.shouldRasterize = true

This is my example. you try customize as you like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM