MoviaBox/ShortPlay/Class/Home/View/SPHomeDataItemView.swift
2025-04-14 16:32:48 +08:00

88 lines
2.1 KiB
Swift

//
// SPHomeDataItemView.swift
// ShortPlay
//
// Created by on 2025/4/14.
//
import UIKit
class SPHomeDataItemView: UIView {
///
static let contentToTop: CGFloat = 36
class func contentHeight(dataArr: [SPShortModel]) -> CGFloat {
return contentToTop
}
override var intrinsicContentSize: CGSize {
let height = Self.contentHeight(dataArr: dataArr ?? [])
return CGSize(width: kSPScreenWidth, height: height)
}
var dataArr: [SPShortModel]? {
didSet {
self.invalidateIntrinsicContentSize()
}
}
private(set) lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = .fontMedium(ofSize: 15)
label.textColor = .colorFFFFFF()
return label
}()
private lazy var moreButton: UIButton = {
let button = UIButton(type: .custom)
button.setTitle("More", for: .normal)
button.setTitleColor(.colorF564B6(), for: .normal)
button.titleLabel?.font = .fontLight(ofSize: 12)
return button
}()
private(set) lazy var contentView: UIView = {
let view = UIView()
return view
}()
override init(frame: CGRect) {
super.init(frame: frame)
_setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension SPHomeDataItemView {
private func _setupUI() {
addSubview(titleLabel)
addSubview(moreButton)
addSubview(contentView)
titleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.top.equalToSuperview()
make.height.equalTo(21)
}
moreButton.snp.makeConstraints { make in
make.centerY.equalTo(moreButton)
make.right.equalToSuperview().offset(-15)
}
contentView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.top.equalTo(Self.contentToTop)
}
}
}