简体   繁体   中英

Outside shadow of a cell in a collection view not showing up swift ios

I am trying to add shadow to the cell but it is not showing up I followed this tutorial

    cell?.layer.cornerRadius = 25
    cell?.layer.shadowColor = UIColor.green.cgColor
    cell?.layer.shadowOpacity = 1
    cell?.layer.shadowOffset = .zero
    cell?.layer.shadowRadius = 10
    cell?.layer.shadowPath = UIBezierPath(rect: cell!.bounds).cgPath
    cell?.layer.shouldRasterize = true
    cell?.layer.rasterizationScale = UIScreen.main.scale

If you set the shadowOffset to 0, the shadow will appear right behind the view and you will see the only the radius of it. Another thing is you must set layer.masksToBounds to false so that the radius of the shadow does not get clipped from the view's bounds.

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