CNLiveShopClassifySwitchTableViewCell.swift
2.39 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
//
// CNLiveShopClassifySwitchTableViewCell.swift
// metaCode
//
// Created by zx on 2023/11/18.
//
import Foundation
///排序类型
enum CNLiveShopClassifySwitchType:Int {
///是否显示分类
case classify
///是否显示导航栏
case nav
}
typealias switchBlock = (_ on:Bool,_ type:CNLiveShopClassifySwitchType)->Void
///包含 Switch的 cell
class CNLiveShopClassifySwitchTableViewCell: UITableViewCell {
var switchType:CNLiveShopClassifySwitchType?
var switchClickBlock:switchBlock?
// MARK: - Lazy
lazy var titlelab: UILabel = {
let titlelab = UILabel.init()
titlelab.textColor = HexColor("#333333")
titlelab.textAlignment = .left
titlelab.font = Font_14
titlelab.adjustsFontSizeToFitWidth=true
return titlelab
}()
lazy var star: UILabel = {
let star = UILabel.init(frame: CGRect(x: 5, y: 0, width: 6, height: 50))
star.textColor = HexColor("#FF725C")
star.textAlignment = .left
star.text = "*"
star.font = Font_12
return star
}()
lazy var rightSwitch: UISwitch = {
let rightSwitch = UISwitch.init()
rightSwitch.tintColor = .green
rightSwitch.addTarget(self, action: #selector(switchAction), for: .valueChanged)
return rightSwitch
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - 初始化UI
func initUI(){
self.contentView.addSubview(self.titlelab)
self.contentView.addSubview(self.star)
self.contentView.addSubview(self.rightSwitch)
self.p_massony()
}
func p_massony(){
self.titlelab.snp.makeConstraints { make in
make.left.equalTo(15)
make.centerY.equalTo(self.contentView.centerY)
}
self.rightSwitch.snp.makeConstraints { make in
make.right.equalTo(-15)
make.centerY.equalTo(self.contentView.centerY)
make.size.equalTo(CGSize(width: 45, height: 22))
}
}
// MARK: - switchAction
@objc func switchAction(sender:UISwitch){
self.switchClickBlock!(self.rightSwitch.isOn, self.switchType!)
}
}