Music_Player3/Pods/JXSegmentedView/Sources/Dot/JXSegmentedDotDataSource.swift
2024-06-03 09:48:39 +08:00

55 lines
2.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// JXSegmentedDotDataSource.swift
// JXSegmentedView
//
// Created by jiaxin on 2018/12/28.
// Copyright © 2018 jiaxin. All rights reserved.
//
import UIKit
open class JXSegmentedDotDataSource: JXSegmentedTitleDataSource {
/// titles
open var dotStates = [Bool]()
/// size
open var dotSize = CGSize(width: 10, height: 10)
/// JXSegmentedViewAutomaticDimensiondotSize.height/2
open var dotCornerRadius: CGFloat = JXSegmentedViewAutomaticDimension
///
open var dotColor = UIColor.red
/// dotViewcentertitleLabeldotOffsetXY
open var dotOffset: CGPoint = CGPoint.zero
open override func preferredItemModelInstance() -> JXSegmentedBaseItemModel {
return JXSegmentedDotItemModel()
}
open override func preferredRefreshItemModel(_ itemModel: JXSegmentedBaseItemModel, at index: Int, selectedIndex: Int) {
super.preferredRefreshItemModel(itemModel, at: index, selectedIndex: selectedIndex)
guard let itemModel = itemModel as? JXSegmentedDotItemModel else {
return
}
itemModel.dotOffset = dotOffset
itemModel.dotState = dotStates[index]
itemModel.dotColor = dotColor
itemModel.dotSize = dotSize
if dotCornerRadius == JXSegmentedViewAutomaticDimension {
itemModel.dotCornerRadius = dotSize.height/2
}else {
itemModel.dotCornerRadius = dotCornerRadius
}
}
//MARK: - JXSegmentedViewDataSource
open override func registerCellClass(in segmentedView: JXSegmentedView) {
segmentedView.collectionView.register(JXSegmentedDotCell.self, forCellWithReuseIdentifier: "cell")
}
open override func segmentedView(_ segmentedView: JXSegmentedView, cellForItemAt index: Int) -> JXSegmentedBaseCell {
let cell = segmentedView.dequeueReusableCell(withReuseIdentifier: "cell", at: index)
return cell
}
}