Created
December 5, 2022 08:52
-
-
Save iamchiwon/43ce3203f911d0dd10f44aab3bbe0f57 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 UIKit | |
@IBDesignable extension UIView { | |
@IBInspectable public var borderColor: UIColor? { | |
get { | |
if let color = layer.borderColor { | |
return UIColor(cgColor: color) | |
} else { | |
return nil | |
} | |
} | |
set { | |
layer.borderColor = newValue!.cgColor | |
} | |
} | |
@IBInspectable public var borderWidth: CGFloat { | |
get { | |
return layer.borderWidth | |
} | |
set { | |
layer.borderWidth = newValue | |
} | |
} | |
@IBInspectable public var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set { | |
layer.cornerRadius = newValue | |
clipsToBounds = newValue > 0 | |
} | |
} | |
@IBInspectable public var shadowColor: UIColor? { | |
get { | |
if let color = layer.shadowColor { | |
return UIColor(cgColor: color) | |
} else { | |
return nil | |
} | |
} | |
set { | |
layer.shadowColor = newValue!.cgColor | |
} | |
} | |
@IBInspectable public var shadowOpacity: Float { | |
get { | |
return layer.shadowOpacity | |
} | |
set { | |
layer.shadowOpacity = newValue | |
} | |
} | |
@IBInspectable public var masksToBounds: Bool { | |
get { | |
return layer.masksToBounds | |
} | |
set { | |
layer.masksToBounds = newValue | |
} | |
} | |
@IBInspectable public var shadowRadius: CGFloat { | |
get { | |
return layer.shadowRadius | |
} | |
set { | |
layer.shadowRadius = newValue | |
} | |
} | |
@IBInspectable public var shadowOffset: CGSize { | |
get { | |
return layer.shadowOffset | |
} | |
set { | |
layer.shadowOffset = newValue | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment