Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override init(frame: CGRect) {
- super.init(frame: frame)
- sharedInit()
- }
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- sharedInit()
- }
- override func prepareForInterfaceBuilder() {
- sharedInit()
- }
- func sharedInit() {
- refreshCorners(value: cornerRadius)
- refreshShadowColor(color: shadowColor)
- refreshShadowOpacity(alpha: shadowAlpha)
- refreshShadowOffset(size: shadowOffset)
- refreshShadowRadius(blur: shadowBlur)
- refreshShadowPath(spread: shadowSpread)
- }
- func refreshCorners(value: CGFloat) {
- layer.cornerRadius = value
- }
- @IBInspectable var cornerRadius: CGFloat = 40 {
- didSet {
- refreshCorners(value: cornerRadius)
- }
- }
- func refreshShadowColor(color: UIColor) {
- layer.shadowColor = color.cgColor
- }
- @IBInspectable var shadowColor: UIColor = .black {
- didSet {
- refreshShadowColor(color: shadowColor)
- }
- }
- func refreshShadowOpacity(alpha: Float) {
- layer.shadowOpacity = alpha
- }
- @IBInspectable var shadowAlpha: Float = 0.16 {
- didSet {
- refreshShadowOpacity(alpha: shadowAlpha)
- }
- }
- func refreshShadowOffset(size: CGSize) {
- layer.shadowOffset = size
- }
- @IBInspectable var shadowOffset: CGSize = CGSize(width: 0, height: 0) {
- didSet {
- refreshShadowOffset(size: shadowOffset)
- }
- }
- func refreshShadowRadius(blur: CGFloat) {
- layer.shadowRadius = blur / 2.0
- }
- @IBInspectable var shadowBlur: CGFloat = 30 {
- didSet {
- refreshShadowRadius(blur: shadowBlur)
- }
- }
- func refreshShadowPath(spread: CGFloat) {
- if spread == 0 {
- layer.shadowPath = nil
- } else {
- let dx = -spread
- let rect = layer.bounds.insetBy(dx: dx, dy: dx)
- layer.shadowPath = UIBezierPath(rect: rect).cgPath
- }
- }
- @IBInspectable var shadowSpread: CGFloat = 0 {
- didSet {
- refreshShadowPath(spread: shadowSpread)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement