MKRingProgressGroupView.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2015 Max Konovalov
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. import UIKit
  21. import MKRingProgressView
  22. @IBDesignable
  23. class RingProgressGroupView: UIView {
  24. let ring1 = RingProgressView()
  25. let ring2 = RingProgressView()
  26. let ring3 = RingProgressView()
  27. @IBInspectable var ring1StartColor: UIColor = .red {
  28. didSet {
  29. ring1.startColor = ring1StartColor
  30. }
  31. }
  32. @IBInspectable var ring1EndColor: UIColor = .blue {
  33. didSet {
  34. ring1.endColor = ring1EndColor
  35. }
  36. }
  37. @IBInspectable var ring2StartColor: UIColor = .red {
  38. didSet {
  39. ring2.startColor = ring2StartColor
  40. }
  41. }
  42. @IBInspectable var ring2EndColor: UIColor = .blue {
  43. didSet {
  44. ring2.endColor = ring2EndColor
  45. }
  46. }
  47. @IBInspectable var ring3StartColor: UIColor = .red {
  48. didSet {
  49. ring3.startColor = ring3StartColor
  50. }
  51. }
  52. @IBInspectable var ring3EndColor: UIColor = .blue {
  53. didSet {
  54. ring3.endColor = ring3EndColor
  55. }
  56. }
  57. @IBInspectable var ringWidth: CGFloat = 20 {
  58. didSet {
  59. ring1.ringWidth = ringWidth
  60. ring2.ringWidth = ringWidth
  61. ring3.ringWidth = ringWidth
  62. setNeedsLayout()
  63. }
  64. }
  65. @IBInspectable var ringSpacing: CGFloat = 2 {
  66. didSet {
  67. setNeedsLayout()
  68. }
  69. }
  70. override init(frame: CGRect) {
  71. super.init(frame: frame)
  72. setup()
  73. }
  74. required init?(coder aDecoder: NSCoder) {
  75. super.init(coder: aDecoder)
  76. setup()
  77. }
  78. private func setup() {
  79. addSubview(ring1)
  80. addSubview(ring2)
  81. addSubview(ring3)
  82. }
  83. override func layoutSubviews() {
  84. super.layoutSubviews()
  85. ring1.frame = bounds
  86. ring2.frame = bounds.insetBy(dx: ringWidth + ringSpacing, dy: ringWidth + ringSpacing)
  87. ring3.frame = bounds.insetBy(dx: 2 * ringWidth + 2 * ringSpacing, dy: 2 * ringWidth + 2 * ringSpacing)
  88. }
  89. }