Created
April 8, 2019 18:32
-
-
Save freddyh/cae2b9d20a7c1b4c6a3a8eb5278fb934 to your computer and use it in GitHub Desktop.
Adds various inspectable elements to UIView
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
extension UIView { | |
@IBInspectable | |
var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set { | |
layer.cornerRadius = newValue | |
} | |
} | |
@IBInspectable | |
var borderColor: UIColor? { | |
get { | |
if let color = layer.borderColor { | |
return UIColor(cgColor: color) | |
} | |
return nil | |
} | |
set { | |
if let color = newValue { | |
layer.borderColor = color.cgColor | |
} else { | |
layer.borderColor = nil | |
} | |
} | |
} | |
@IBInspectable | |
var borderWidth: CGFloat { | |
get { | |
return layer.borderWidth | |
} | |
set { | |
layer.borderWidth = newValue | |
} | |
} | |
@IBInspectable | |
var shadowRadius: CGFloat { | |
get { | |
return layer.shadowRadius | |
} | |
set { | |
layer.shadowRadius = newValue | |
} | |
} | |
@IBInspectable | |
var shadowOpacity: Float { | |
get { | |
return layer.shadowOpacity | |
} | |
set { | |
layer.shadowOpacity = newValue | |
} | |
} | |
@IBInspectable | |
var shadowOffset: CGSize { | |
get { | |
return layer.shadowOffset | |
} | |
set { | |
layer.shadowOffset = newValue | |
} | |
} | |
@IBInspectable | |
var shadowColor: UIColor? { | |
get { | |
if let color = layer.shadowColor { | |
return UIColor(cgColor: color) | |
} | |
return nil | |
} | |
set { | |
if let color = newValue { | |
layer.shadowColor = color.cgColor | |
} else { | |
layer.shadowColor = nil | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment