Guest User

Untitled

a guest
Apr 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. //
  2. // DesignableControl.swift
  3. //
  4.  
  5. import UIKit
  6.  
  7. @IBDesignable
  8. class DesignableControl: UIControl {
  9. @IBInspectable var cornerRadius: CGFloat = 0.0 {
  10. didSet {
  11. self.layer.cornerRadius = self.cornerRadius
  12. }
  13. }
  14.  
  15. @IBInspectable var roundView: Bool = false
  16.  
  17. @IBInspectable var borderColor: UIColor = .clear {
  18. didSet {
  19. self.layer.borderColor = self.borderColor.cgColor
  20. }
  21. }
  22.  
  23. @IBInspectable var borderWidth: CGFloat = 0.0 {
  24. didSet {
  25. self.layer.borderWidth = self.borderWidth
  26. }
  27. }
  28.  
  29. @IBInspectable var shadowColor: UIColor = .clear {
  30. didSet {
  31. self.layer.shadowColor = self.shadowColor.cgColor
  32. }
  33. }
  34.  
  35. @IBInspectable var shadowOpacity: Float = 0.0 {
  36. didSet {
  37. self.layer.shadowOpacity = self.shadowOpacity
  38. }
  39. }
  40.  
  41. @IBInspectable var shadowOffset: CGSize = .zero {
  42. didSet {
  43. self.layer.shadowOffset = self.shadowOffset
  44. }
  45. }
  46.  
  47. @IBInspectable var shadowRadius: CGFloat = 0.0 {
  48. didSet {
  49. self.layer.shadowRadius = self.shadowRadius
  50. }
  51. }
  52.  
  53. @IBInspectable var gradientStartColor: UIColor = .clear {
  54. didSet {
  55. if let layer = self.layer as? CAGradientLayer {
  56. layer.colors = [self.gradientStartColor.cgColor, self.gradientEndColor.cgColor]
  57. }
  58. }
  59. }
  60.  
  61. @IBInspectable var gradientEndColor: UIColor = .clear {
  62. didSet {
  63. if let layer = self.layer as? CAGradientLayer {
  64. layer.colors = [self.gradientStartColor.cgColor, self.gradientEndColor.cgColor]
  65. }
  66. }
  67. }
  68.  
  69. @IBInspectable var gradientStart: CGPoint = CGPoint(x: 0.0, y: 1.0) {
  70. didSet {
  71. if let layer = self.layer as? CAGradientLayer {
  72. layer.startPoint = self.gradientStart
  73. }
  74. }
  75. }
  76.  
  77. @IBInspectable var gradientEnd: CGPoint = CGPoint(x: 1.0, y: 0.0) {
  78. didSet {
  79. if let layer = self.layer as? CAGradientLayer {
  80. layer.endPoint = self.gradientEnd
  81. }
  82. }
  83. }
  84.  
  85. override class var layerClass: AnyClass {
  86. return CAGradientLayer.self
  87. }
  88.  
  89. override func layoutSubviews() {
  90. super.layoutSubviews()
  91. self.layer.cornerRadius = self.roundView ? (min(self.bounds.width, self.bounds.height) / 2.0) : self.cornerRadius
  92. }
  93.  
  94. override func prepareForInterfaceBuilder() {
  95. super.prepareForInterfaceBuilder()
  96. self.layer.cornerRadius = self.roundView ? (min(self.bounds.width, self.bounds.height) / 2.0) : self.cornerRadius
  97. }
  98. }
Add Comment
Please, Sign In to add comment