MoviaBox/ShortPlay/Class/Home/View/SPSearchAssociativeCell.swift
2025-04-19 09:20:15 +08:00

76 lines
2.0 KiB
Swift

//
// SPSearchAssociativeCell.swift
// ShortPlay
//
// Created by on 2025/4/18.
//
import UIKit
class SPSearchAssociativeCell: SPTableViewCell {
var searchText: String?
var model: SPShortModel? {
didSet {
if let string = model?.titleAttributedString {
titleLabel.attributedText = string
} else {
let string = NSMutableAttributedString(string: model?.name ?? "")
string.color = .color8A899F()
if let range = model?.name?.ocString().range(of: searchText ?? "") {
string.setColor(.colorFFFFFF(), range: range)
}
titleLabel.attributedText = string
}
}
}
private lazy var iconImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "play_icon_03"))
return imageView
}()
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = .fontRegular(ofSize: 14)
return label
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
_setupUI()
}
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension SPSearchAssociativeCell {
private func _setupUI() {
contentView.addSubview(iconImageView)
contentView.addSubview(titleLabel)
iconImageView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalToSuperview().offset(15)
}
titleLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalToSuperview().offset(40)
make.right.lessThanOrEqualToSuperview().offset(-15)
}
}
}