Skip to content

Instantly share code, notes, and snippets.

@asmarques
Created May 15, 2017 06:55
Show Gist options
  • Save asmarques/14724e659837269d5b2702c8b8b26801 to your computer and use it in GitHub Desktop.
Save asmarques/14724e659837269d5b2702c8b8b26801 to your computer and use it in GitHub Desktop.
UIView shadows in Interface Builder
import UIKit
extension UIView {
@IBInspectable var shadowColor: UIColor? {
set {
layer.shadowColor = newValue?.cgColor
}
get {
if let color = layer.shadowColor {
return UIColor(cgColor: color)
}
else {
return nil
}
}
}
@IBInspectable var shadowOpacity: Float {
set {
layer.shadowOpacity = newValue
}
get {
return layer.shadowOpacity
}
}
@IBInspectable var shadowOffset: CGPoint {
set {
layer.shadowOffset = CGSize(width: newValue.x, height: newValue.y)
}
get {
return CGPoint(x: layer.shadowOffset.width, y:layer.shadowOffset.height)
}
}
@IBInspectable var shadowRadius: CGFloat {
set {
layer.shadowRadius = newValue
}
get {
return layer.shadowRadius
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment