CNLivePlayletHomePageHeaderCell.swift
6.73 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// CNLivePlayletHomePageHeaderCell.swift
// metaCode
//
// Created by zx on 2024/1/4.
// 短剧主页-头视图Cell
import Foundation
import QMUIKit
import SwiftUI
import SnapKit
class CNLivePlayletHomePageHeaderCell:UITableViewCell{
//MARK: - 懒加载
lazy var iconImgView :UIImageView = {
let iconImgView = UIImageView(frame: CGRect(x: 20, y: 20, width: 100, height: 100))
return iconImgView
}()
///标题
lazy var titleLabl: UILabel = {
let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.right+10, self.iconImgView.top+20, KSreenWidth-(self.iconImgView.right+15)-10, 21))
titleLabel.textColor = HexColor("#333333")
titleLabel.textAlignment = .left
titleLabel.font = Font_20
titleLabel.text = "啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"
let height = titleLabel.qmui_lineHeight
titleLabel.height = height
return titleLabel
}()
///集数
lazy var jishuLabel: UILabel = {
let titleLabel = UILabel.init(frame: CGRectMake(self.titleLabl.left, self.titleLabl.bottom+20, 40, 21))
titleLabel.textColor = HexColor("#333333")
titleLabel.textAlignment = .left
titleLabel.font = Font_15
titleLabel.text = "45集"
let height = titleLabel.qmui_lineHeight
titleLabel.height = height
return titleLabel
}()
///简介
lazy var jianjieLabel: UILabel = {
let titleLabel = UILabel.init(frame: CGRectMake(self.iconImgView.left, self.iconImgView.bottom+10, KSreenWidth-2*self.iconImgView.left, 21))
titleLabel.textColor = HexColor("#333333")
titleLabel.textAlignment = .left
titleLabel.font = Font_14
titleLabel.text = "啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈"
titleLabel.numberOfLines = 0
var lines = titleLabel.getRealLabelTextLines()
let height = titleLabel.qmui_lineHeight
if lines > 2 {
lines = 2
}
titleLabel.height = height*CGFloat(lines)
return titleLabel
}()
//展开,收起
lazy var expandBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .white
expandBtn.frame = CGRect(x: self.jianjieLabel.right-60, y: self.jianjieLabel.bottom, width: 60, height: 30)
expandBtn.setTitle("展开", for: .normal)
expandBtn.setTitle("收起", for: .selected)
expandBtn.setTitleColor(HexColor("#333333"), for: .normal)
expandBtn.setImage(UIImage(named: "DS_coupon_unSelect"), for: .normal)
expandBtn.setImage(UIImage(named: "DS_coupon_unSelect"), for: .selected)
expandBtn.titleLabel?.font = Font_16
expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .right)
expandBtn.addTarget(self, action: #selector(expandBtnAction), for: .touchUpInside)
return expandBtn
}()
//追剧|已追剧
lazy var followBtn: UIButton = {
let followBtn = UIButton(type: .custom)
followBtn.setTitle("追剧", for: .normal)
followBtn.setTitleColor(.black, for: .normal)
followBtn.setTitleColor(.black, for: .selected)
followBtn.setTitle("已追剧", for: .selected)
followBtn.layer.borderColor = UIColor.black.cgColor
followBtn.layer.borderWidth = 1
followBtn.layer.cornerRadius = 3
followBtn.clipsToBounds = true
followBtn.addTarget(self, action: #selector(followBtnAction), for: .touchUpInside)
return followBtn
}()
//付费解锁全集|已购买
lazy var paymentBtn: UIButton = {
let paymentBtn = UIButton(type: .custom)
paymentBtn.setTitle("付费解锁全集", for: .normal)
paymentBtn.setTitleColor(.white, for: .normal)
paymentBtn.setTitle("已购买", for: .selected)
paymentBtn.setTitleColor(.black, for: .selected)
paymentBtn.backgroundColor = .blue
paymentBtn.layer.borderColor = UIColor.black.cgColor
paymentBtn.layer.borderWidth = 1
paymentBtn.layer.cornerRadius = 3
paymentBtn.clipsToBounds = true
paymentBtn.addTarget(self, action: #selector(paymentBtnAction), for: .touchUpInside)
return paymentBtn
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
self.setUI()
}
func setUI(){
self.contentView.addSubview(self.iconImgView)
self.contentView.addSubview(self.titleLabl)
self.contentView.addSubview(self.jishuLabel)
self.contentView.addSubview(self.jianjieLabel)
self.contentView.addSubview(self.expandBtn)
self.contentView.addSubview(self.followBtn)
self.contentView.addSubview(self.paymentBtn)
let lines = jianjieLabel.getRealLabelTextLines()
if lines <= 2{
self.expandBtn.isHidden = true
}else{
self.expandBtn.isHidden = false
}
self.followBtn.snp.makeConstraints { make in
make.top.equalTo(self.jianjieLabel.snp.bottom).offset(40)
make.left.equalTo(self.jianjieLabel.snp.left).offset(30)
make.width.equalTo(120)
make.height.equalTo(30)
}
self.paymentBtn.snp.makeConstraints { make in
make.top.equalTo(self.followBtn)
make.left.equalTo(self.followBtn.snp.left).offset(KSreenWidth/2)
make.width.equalTo(120)
make.height.equalTo(30)
}
self.iconImgView.backgroundColor = .red
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Action
@objc func expandBtnAction(button:UIButton){
button.isSelected = !button.isSelected
let lines = jianjieLabel.getRealLabelTextLines()
let height = jianjieLabel.qmui_lineHeight
if button.isSelected{
//文本收起状态,点击展开
self.jianjieLabel.height = CGFloat(lines)*height
}else{
//文本展开状态,点击收起
self.jianjieLabel.height = 2*height
}
self.expandBtn.top = self.jianjieLabel.bottom
}
@objc func followBtnAction(button:UIButton){
button.isSelected = !button.isSelected
}
@objc func paymentBtnAction(button:UIButton){
button.isSelected = !button.isSelected
}
}