iOS Layer 阴影效果不显示问题

设置阴影时,又去设置 masksToBounds = true 阴影效果就不会显示。

        let shadowView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        shadowView.backgroundColor = .yellow
        shadowView.layer.shadowColor = UIColor.black.cgColor
        shadowView.layer.shadowOffset = CGSize(width: 5, height: 5)
        shadowView.layer.shadowOpacity = 1
        shadowView.layer.shadowRadius = 10
        
        shadowView.layer.cornerRadius = 5
        //  设置阴影 又同时设置 masksToBounds 会被裁剪掉,效果不显示
        // shadowView.layer.masksToBounds = true
        view.addSubview(shadowView)

你可能感兴趣的:(iOS Layer 阴影效果不显示问题)