Created
May 15, 2017 06:55
-
-
Save asmarques/14724e659837269d5b2702c8b8b26801 to your computer and use it in GitHub Desktop.
UIView shadows in Interface Builder
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
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