iOS Layer 阴影效果不显示问题
2020-03-22 本文已影响0人
风儿吹啊吹
设置阴影时,又去设置 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)