Last active
June 5, 2019 11:32
-
-
Save sunnyleeyun/913d79dd77338146761e143584c72d6a to your computer and use it in GitHub Desktop.
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 Foundation | |
import UIKit | |
@IBDesignable | |
class DesignableView: UIView { | |
} | |
@IBDesignable | |
class DesignableButton: UIButton { | |
} | |
@IBDesignable | |
class DesignableLabel: UILabel { | |
} | |
extension UIView { | |
@IBInspectable | |
var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set { | |
layer.cornerRadius = newValue | |
} | |
} | |
@IBInspectable | |
var borderWidth: CGFloat { | |
get { | |
return layer.borderWidth | |
} | |
set { | |
layer.borderWidth = 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 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