JXSegmentedIndicatorRainbowLineView.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // JXSegmentedIndicatorRainbowLineView.swift
  3. // JXSegmentedView
  4. //
  5. // Created by jiaxin on 2018/12/28.
  6. // Copyright © 2018 jiaxin. All rights reserved.
  7. //
  8. import UIKit
  9. /// 会无视indicatorColor属性,以indicatorColors为准
  10. open class JXSegmentedIndicatorRainbowLineView: JXSegmentedIndicatorLineView {
  11. /// 数量需要与item的数量相等。默认空数组,必须要赋值该属性。segmentedView在reloadData的时候,也要一并更新该属性,不然会出现数组越界。
  12. open var indicatorColors = [UIColor]()
  13. open override func refreshIndicatorState(model: JXSegmentedIndicatorParamsModel) {
  14. super.refreshIndicatorState(model: model)
  15. backgroundColor = indicatorColors[model.currentSelectedIndex]
  16. }
  17. open override func contentScrollViewDidScroll(model: JXSegmentedIndicatorParamsModel) {
  18. super.contentScrollViewDidScroll(model: model)
  19. if model.percent == 0 || !isScrollEnabled {
  20. //model.percent等于0时不需要处理,会调用selectItem(model: JXSegmentedIndicatorParamsModel)方法处理
  21. //isScrollEnabled为false不需要处理
  22. return
  23. }
  24. backgroundColor = JXSegmentedViewTool.interpolateColor(from: indicatorColors[model.leftIndex], to: indicatorColors[model.rightIndex], percent: model.percent)
  25. }
  26. open override func selectItem(model: JXSegmentedIndicatorParamsModel) {
  27. super.selectItem(model: model)
  28. backgroundColor = indicatorColors[model.currentSelectedIndex]
  29. }
  30. }