Ios 表视图单元格内的阴影不工作
我牢房里的阴影根本不起作用 这是我想添加阴影的视图之一,但它不起作用。我在自定义单元格类中添加了此代码Ios 表视图单元格内的阴影不工作,ios,swift,iphone,xcode,Ios,Swift,Iphone,Xcode,我牢房里的阴影根本不起作用 这是我想添加阴影的视图之一,但它不起作用。我在自定义单元格类中添加了此代码 super.layoutSubviews() UIview1.layer.cornerRadius = 7 UIview1.layer.borderWidth = 1.0 UIview1.layer.borderColor = HexColor.hexStringToUIColor(hex: "FA2537").cgCol
super.layoutSubviews()
UIview1.layer.cornerRadius = 7
UIview1.layer.borderWidth = 1.0
UIview1.layer.borderColor = HexColor.hexStringToUIColor(hex: "FA2537").cgColor
UIview1.layer.masksToBounds = true
UIview1.layer.shadowColor = HexColor.hexStringToUIColor(hex: "01A4B7").cgColor
UIview1.layer.shadowOpacity = 0.5
UIview1.layer.shadowOffset = CGSize.zero
UIview1.layer.shadowRadius = 5
}
显然,我需要将maskToBounds改为false而不是true
UIview1.layer.masksToBounds=false
要在视图上显示阴影,需要设置其层的masksToBounds属性false
或者你可以试试这个
您可以创建这样的方法,并可以使用:
extension UIView {
func setShadowWith(color: UIColor = UIColor.black, shadowOpacity: Float = 0.2, radius: Float = 1.0, shadowOffSet: CGSize = CGSize(width: 0, height: 1)) {
self.layer.shadowColor = color.cgColor
self.layer.shadowOpacity = shadowOpacity
self.layer.shadowOffset = shadowOffSet
self.layer.shadowRadius = CGFloat(radius)
}
}
并且可以使用如下函数
yourContainerView.setShadowWith()
这里,函数中使用的参数采用默认值。你可以相应地改变
快乐编码:)