- UIView添加四边阴影效果
简单的一个函数,使用的swift语言
func addShadowToView(_ theView: UIView,_ theColor: UIColor) {
theView.layer.shadowColor = theColor.cgColor
theView.layer.shadowOffset = CGSize(width: 0, height: 0)
theView.layer.shadowOpacity = 0.5
theView.layer.shadowRadius = 5
}
- UIView添加单边阴影效果
func addShadowToView(_ theView: UIView,_ theColor: UIColor) {
theView.layer.shadowColor = theColor.cgColor
theView.layer.shadowOffset = CGSize(width: 0, height: 0)
theView.layer.shadowOpacity = 0.5
theView.layer.shadowRadius = 5
// 单边阴影 顶边
let shadowPathWidth = theView.layer.shadowRadius
let shadowRect = CGRect(x: 0, y: 0-shadowPathWidth/2.0, width: theView.bounds.size.width, height: shadowPathWidth)
let path = UIBezierPath.init(rect: shadowRect)
theView.layer.shadowPath = path.cgPath
}