Why masksToBounds = YES prevents CALayer shadow?

后端 未结 6 1250
借酒劲吻你
借酒劲吻你 2020-11-28 01:44

With the following snippet, I\'m adding a drop shadow effect to one my UIView. Which works pretty well. But as soon as I set the view\'s masksToBounds prope

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 02:33

    Here is one of the solutions:

         @IBOutlet private weak var blockView: UIView! {
             didSet {
              blockView.backgroundColor = UIColor.white
              blockView.layer.shadowColor = UIColor.black.cgColor
              blockView.layer.shadowOpacity = 0.5
              blockView.layer.shadowOffset = CGSize.zero
    
              blockView.layer.cornerRadius = 10
            }
          }
          @IBOutlet private weak var imageView: UIImageView! {
            didSet {
              imageView.layer.cornerRadius = 10
              imageView.layer.masksToBounds = true
    
              imageView.layer.shouldRasterize = true
            }
          }
    

提交回复
热议问题