|
@@ -14,7 +14,7 @@ class PQCustomSwitchView: UIView {
|
|
|
/// 按钮点击的回调
|
|
|
var switchChangeHandle: ((_ sender: UIButton) -> Void)?
|
|
|
|
|
|
- var saveBtn:Array<UIButton> = Array.init()
|
|
|
+ var saveBtns:Array<UIButton> = Array.init()
|
|
|
|
|
|
override private init(frame: CGRect) {
|
|
|
super.init(frame: frame)
|
|
@@ -24,6 +24,14 @@ class PQCustomSwitchView: UIView {
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 服务器返回的 (1:快节奏,2:适中,3:慢节奏) ,
|
|
|
+ 一,快慢速模式下取卡点 2 3 4
|
|
|
+ 二,跳跃卡点模式下根据不同速度 取卡点 1,2,3
|
|
|
+ 快节奏为选中区域的所有点位,即0,1,2,3,4 5 6 7 8 9 10 ……
|
|
|
+ 适中为每两个点位取一个,即0,2,4,6……
|
|
|
+ 慢节奏为每三个点位取一个,即0,3,6,9……
|
|
|
+ */
|
|
|
init(frame: CGRect, titles: [String], defaultIndex: Int = 1) {
|
|
|
super.init(frame: frame)
|
|
|
BFLog(message: "初始时选择的位置 is \(defaultIndex)")
|
|
@@ -32,14 +40,13 @@ class PQCustomSwitchView: UIView {
|
|
|
let itemBtn = UIButton(type: .custom)
|
|
|
//8 是每一个btn 的间隔
|
|
|
itemBtn.frame = CGRect(x: CGFloat(index) * itemWidth + CGFloat(index) * 8, y: 0, width: itemWidth, height: frame.height)
|
|
|
- itemBtn.tag = index + 1
|
|
|
+ itemBtn.tag = (3 - index)
|
|
|
itemBtn.setTitle(itemTitle, for: .normal)
|
|
|
itemBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#959595"), for: .normal)
|
|
|
itemBtn.setTitleColor(UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue), for: .selected)
|
|
|
itemBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
|
|
|
|
|
|
- itemBtn.isSelected = index == (defaultIndex - 1)
|
|
|
- if index == (defaultIndex - 1) {
|
|
|
+ if itemBtn.tag == defaultIndex {
|
|
|
itemBtn.isSelected = true
|
|
|
|
|
|
currentItemBtn = itemBtn
|
|
@@ -54,13 +61,18 @@ class PQCustomSwitchView: UIView {
|
|
|
itemBtn.addCorner(corner:5)
|
|
|
addSubview(itemBtn)
|
|
|
|
|
|
- saveBtn.append(itemBtn)
|
|
|
+ saveBtns.append(itemBtn)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func selectOneBtn(Index:Int) {
|
|
|
- BFLog(message: "选择节奏 \(Index)")
|
|
|
- updateSelectBtn(sender: saveBtn[Index])
|
|
|
+
|
|
|
+ let selectIndex = saveBtns.firstIndex(where: { (svaeBtn) -> Bool in
|
|
|
+
|
|
|
+ (svaeBtn.tag == Index)
|
|
|
+ })
|
|
|
+ BFLog(message: "选择节奏 \(selectIndex ?? -1)")
|
|
|
+ updateSelectBtn(sender: saveBtns[selectIndex ?? 0])
|
|
|
}
|
|
|
|
|
|
func updateSelectBtn(sender: UIButton) {
|