Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBDesignable extension UIView {
- /* The color of the shadow. Defaults to opaque black. Colors created
- * from patterns are currently NOT supported. Animatable. */
- @IBInspectable var shadowColor: UIColor? {
- set {
- layer.shadowColor = newValue!.cgColor
- }
- get {
- if let color = layer.shadowColor {
- return UIColor(cgColor:color)
- }
- else {
- return nil
- }
- }
- }
- /* The opacity of the shadow. Defaults to 0. Specifying a value outside the
- * [0,1] range will give undefined results. Animatable. */
- @IBInspectable var shadowOpacity: Float {
- set {
- layer.shadowOpacity = newValue
- }
- get {
- return layer.shadowOpacity
- }
- }
- /* The shadow offset. Defaults to (0, -3). Animatable. */
- @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)
- }
- }
- /* The blur radius used to create the shadow. Defaults to 3. Animatable. */
- @IBInspectable var shadowRadius: CGFloat {
- set {
- layer.shadowRadius = newValue
- }
- get {
- return layer.shadowRadius
- }
- }
- func addDropShadowToView() {
- layer.masksToBounds = false
- layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.25).cgColor
- layer.shadowOffset = CGSize(width: 2.5, height: 3.3)
- layer.shadowRadius = 3.3
- layer.shadowOpacity = 1.0
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement