Last active
November 23, 2018 08:13
-
-
Save muhlenXi/f05e49eb66286ef4e93815f8b30ac4d7 to your computer and use it in GitHub Desktop.
给view添加阴影
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension UIView { | |
/// 添加阴影效果 | |
func setShadow(color: UIColor = UIColor.black, opacity: Float = 0.5, offset: CGSize = CGSize(width: 0, height: 0)) { | |
// 添加阴影 | |
self.layer.shadowColor = color.cgColor | |
// 阴影的透明度 | |
self.layer.shadowOpacity = opacity | |
// 阴影的偏移 | |
self.layer.shadowOffset = offset | |
// 避免离屏渲染带来卡顿 | |
self.layer.shadowPath = UIBezierPath(rect: bounds).cgPath | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment