CNLiveShopClassifySectionHeaderView.swift
5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// CNLiveShopClassifySectionHeaderView.swift
// metaCode
//
// Created by zx on 2023/12/12.
//
import Foundation
typealias showChildCalssifyActionBlock = (_ section:Int ,_ classifyModel:CNLiveShopClassifyModel)->Void
typealias addSubClassifyBtnActionBlock = (_ classifyModel:CNLiveShopClassifyModel)->Void
typealias editBtnActionBlock = (_ classifyModel:CNLiveShopClassifyModel)->Void
class CNLiveShopClassifySectionHeaderView:UITableViewHeaderFooterView{
///当前分区
var section:Int = 0
/// 分类model
var _classifyModel:CNLiveShopClassifyModel?
var classifyModel:CNLiveShopClassifyModel?{
get{
_classifyModel
}
set{
_classifyModel = newValue
self.classifyNameBtn.isSelected = _classifyModel!.showChild
self.classifyNameBtn.setTitle(_classifyModel!.title, for: .normal)
self.sortLab.text = _classifyModel!.ord
if Int(_classifyModel!.state ?? "") == 2{
self.showSwitch.isOn = true
}else{
self.showSwitch.isOn = false
}
}
}
///点击显示/隐藏 子分类事件回调
var showChildCalssifyBlock:showChildCalssifyActionBlock?
///点击添加子分类事件回调
var addSubClassifyBtnBlock:addSubClassifyBtnActionBlock?
///点击编辑事件回调
var editBtnBlock:editBtnActionBlock?
///分类名称
lazy var classifyNameBtn: UIButton = {
let classifyNameBtn = UIButton(type: .custom)
classifyNameBtn.frame = CGRect(x: 0, y: 0, width: KSreenWidth*0.3, height: 50)
classifyNameBtn.setImage(UIImage(named: "DS_shopclassily_down"), for: .normal)
classifyNameBtn.setImage(UIImage(named: "DS_shopclassily_up"), for: .selected)
classifyNameBtn.setTitleColor(HexColor("#333333"), for: .normal)
classifyNameBtn.setTitle("分类", for: .normal)
classifyNameBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .right)
classifyNameBtn.titleLabel?.font = Font_14
classifyNameBtn.addTarget(self, action: #selector(showChildCalssifyAction), for: .touchUpInside)
return classifyNameBtn
}()
///排序名称
lazy var sortLab: UILabel = {
let sortLab = UILabel.init(frame: CGRectMake(self.classifyNameBtn.right, 0, KSreenWidth*0.2, 50))
sortLab.text = "排序"
sortLab.textColor = HexColor("#333333")
sortLab.textAlignment = .center
sortLab.font = Font_14
sortLab.adjustsFontSizeToFitWidth=true
return sortLab
}()
///是否显示
lazy var showSwitch :UISwitch = {
let showSwitch = UISwitch(frame: CGRect(x: self.sortLab.right+10, y: 10, width: KSreenWidth*0.2, height: 50))
showSwitch.isEnabled = false
return showSwitch
}()
///添加子分类
lazy var addSubClassifyBtn: UIButton = {
let addSubClassifyBtn = UIButton(type: .custom)
addSubClassifyBtn.frame = CGRect(x: self.showSwitch.right, y: 0, width: KSreenWidth*0.21, height: 50)
addSubClassifyBtn.setTitle("添加子类", for: .normal)
addSubClassifyBtn.setTitleColor(HexColor("#0091FF"), for: .normal)
addSubClassifyBtn.titleLabel?.font = Font_14
addSubClassifyBtn.addTarget(self, action: #selector(addSubClassifyBtnAction), for: .touchUpInside)
return addSubClassifyBtn
}()
///编辑
lazy var editBtn: UIButton = {
let editBtn = UIButton(type: .custom)
editBtn.frame = CGRect(x: self.addSubClassifyBtn.right, y: 0, width: KSreenWidth*0.09, height: 50)
editBtn.setTitle("编辑", for: .normal)
editBtn.setTitleColor(HexColor("#0091FF"), for: .normal)
editBtn.titleLabel?.font = Font_14
editBtn.addTarget(self, action: #selector(editBtnAction), for: .touchUpInside)
return editBtn
}()
/// 底部线
lazy var bottomLine: UILabel = {
let bottomLine = UILabel.init(frame: CGRectMake(0, 49, KSreenWidth, 1))
bottomLine.backgroundColor = HexColor("#E4E4E4")
return bottomLine
}()
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
self.initUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - 初始化UI
func initUI(){
self.contentView.backgroundColor = .white
self.contentView.addSubview(self.classifyNameBtn)
self.contentView.addSubview(self.sortLab)
self.contentView.addSubview(self.showSwitch)
self.contentView.addSubview(self.addSubClassifyBtn)
self.contentView.addSubview(self.editBtn)
self.contentView.addSubview(self.bottomLine)
}
// MARK: - response method
///显示子分类
@objc func showChildCalssifyAction(){
self.showChildCalssifyBlock!(self.section, self.classifyModel!)
}
///添加子分类
@objc func addSubClassifyBtnAction(){
self.addSubClassifyBtnBlock!(self.classifyModel!)
}
/// 编辑
@objc func editBtnAction(){
self.editBtnBlock!(self.classifyModel!)
}
}