Skip to content

Instantly share code, notes, and snippets.

@Akhu
Created May 12, 2017 09:37
Show Gist options
  • Save Akhu/7e3d867d4b7563a740cb8bbe2abb69cd to your computer and use it in GitHub Desktop.
Save Akhu/7e3d867d4b7563a740cb8bbe2abb69cd to your computer and use it in GitHub Desktop.
Some effect compilation to apply to UIView
extension UIView {
func round(roundValue:CGFloat? = nil) {
if roundValue != nil {
layer.cornerRadius = roundValue!
}else {
layer.cornerRadius = self.layer.bounds.width/2
}
layer.masksToBounds = true
self.clipsToBounds = true
}
/**
Note : You have to create 2 view if you want to create dropShadow effect combined with rounded border
*/
open func addDropShadow(withOffset offset: CGSize, color:CGColor, radius: CGFloat = 6.0, opacity:CGFloat = 0.4) {
let layer = self.layer
layer.shadowColor = UIColor.black.cgColor
layer.shadowOffset = offset
layer.shadowRadius = 6.0
layer.shadowOpacity = 0.4
layer.masksToBounds = false
updateShadowPath()
}
private func updateShadowPath() {
layer.shadowPath = UIBezierPath(roundedRect: layer.bounds, cornerRadius: layer.cornerRadius).cgPath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment