Skip to content

Instantly share code, notes, and snippets.

@muhlenXi
Last active November 23, 2018 08:13
Show Gist options
  • Save muhlenXi/f05e49eb66286ef4e93815f8b30ac4d7 to your computer and use it in GitHub Desktop.
Save muhlenXi/f05e49eb66286ef4e93815f8b30ac4d7 to your computer and use it in GitHub Desktop.
给view添加阴影
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