AnimatableSlider.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // Created by Tom Baranes on 25/06/16.
  3. // Copyright © 2016 IBAnimatable. All rights reserved.
  4. //
  5. import UIKit
  6. @IBDesignable
  7. open class AnimatableSlider: UISlider, SliderImagesDesignable, BorderDesignable, RotationDesignable, ShadowDesignable, Animatable {
  8. // MARK: - SliderImagesDesignable
  9. @IBInspectable open var thumbImage: UIImage? {
  10. didSet {
  11. configureThumbImage()
  12. }
  13. }
  14. @IBInspectable open var thumbHighlightedImage: UIImage? {
  15. didSet {
  16. configureThumbImage()
  17. }
  18. }
  19. @IBInspectable open var minimumTrackImage: UIImage? {
  20. didSet {
  21. configureMinimumTrackImage()
  22. }
  23. }
  24. @IBInspectable open var minimumTrackHighlightedImage: UIImage? {
  25. didSet {
  26. configureMinimumTrackImage()
  27. }
  28. }
  29. @IBInspectable open var maximumTrackImage: UIImage? {
  30. didSet {
  31. configureMaximumTrackImage()
  32. }
  33. }
  34. @IBInspectable open var maximumTrackHighlightedImage: UIImage? {
  35. didSet {
  36. configureMaximumTrackImage()
  37. }
  38. }
  39. // MARK: - BorderDesignable
  40. open var borderType: BorderType = .solid {
  41. didSet {
  42. configureBorder()
  43. }
  44. }
  45. @IBInspectable var _borderType: String? {
  46. didSet {
  47. borderType = BorderType(string: _borderType)
  48. }
  49. }
  50. @IBInspectable open var borderColor: UIColor? {
  51. didSet {
  52. configureBorder()
  53. }
  54. }
  55. @IBInspectable open var borderWidth: CGFloat = CGFloat.nan {
  56. didSet {
  57. configureBorder()
  58. }
  59. }
  60. open var borderSides: BorderSides = .AllSides {
  61. didSet {
  62. configureBorder()
  63. }
  64. }
  65. @IBInspectable var _borderSides: String? {
  66. didSet {
  67. borderSides = BorderSides(rawValue: _borderSides)
  68. }
  69. }
  70. // MARK: - RotationDesignable
  71. @IBInspectable open var rotate: CGFloat = CGFloat.nan {
  72. didSet {
  73. configureRotate()
  74. }
  75. }
  76. // MARK: - ShadowDesignable
  77. @IBInspectable open var shadowColor: UIColor? {
  78. didSet {
  79. configureShadowColor()
  80. }
  81. }
  82. @IBInspectable open var shadowRadius: CGFloat = CGFloat.nan {
  83. didSet {
  84. configureShadowRadius()
  85. }
  86. }
  87. @IBInspectable open var shadowOpacity: CGFloat = CGFloat.nan {
  88. didSet {
  89. configureShadowOpacity()
  90. }
  91. }
  92. @IBInspectable open var shadowOffset: CGPoint = CGPoint(x: CGFloat.nan, y: CGFloat.nan) {
  93. didSet {
  94. configureShadowOffset()
  95. }
  96. }
  97. // MARK: - Animatable
  98. open var animationType: AnimationType = .none
  99. @IBInspectable var _animationType: String? {
  100. didSet {
  101. animationType = AnimationType(string: _animationType)
  102. }
  103. }
  104. @IBInspectable open var autoRun: Bool = true
  105. @IBInspectable open var duration: Double = Double.nan
  106. @IBInspectable open var delay: Double = Double.nan
  107. @IBInspectable open var damping: CGFloat = CGFloat.nan
  108. @IBInspectable open var velocity: CGFloat = CGFloat.nan
  109. @IBInspectable open var force: CGFloat = CGFloat.nan
  110. @IBInspectable var _timingFunction: String = "" {
  111. didSet {
  112. timingFunction = TimingFunctionType(string: _timingFunction)
  113. }
  114. }
  115. open var timingFunction: TimingFunctionType = .none
  116. // MARK: - Lifecycle
  117. open override func prepareForInterfaceBuilder() {
  118. super.prepareForInterfaceBuilder()
  119. configureInspectableProperties()
  120. }
  121. open override func awakeFromNib() {
  122. super.awakeFromNib()
  123. configureInspectableProperties()
  124. }
  125. open override func layoutSubviews() {
  126. super.layoutSubviews()
  127. configureAfterLayoutSubviews()
  128. autoRunAnimation()
  129. }
  130. // MARK: - Private
  131. fileprivate func configureInspectableProperties() {
  132. configureAnimatableProperties()
  133. }
  134. fileprivate func configureAfterLayoutSubviews() {
  135. configureBorder()
  136. }
  137. }