// // SPSearchAssociativeCell.swift // Thimra // // 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 = .colorEAF7FF() if let range = model?.name?.lowercased().ocString().range(of: (searchText ?? "").lowercased()) { string.setColor(.colorFF4B5A(), range: range) } titleLabel.attributedText = string } } } private lazy var iconImageView: UIImageView = { let imageView = UIImageView(image: UIImage(named: "play_icon_03")) imageView.setContentHuggingPriority(.required, for: .horizontal) imageView.setContentCompressionResistancePriority(.required, for: .horizontal) 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(16) } titleLabel.snp.makeConstraints { make in make.centerY.equalToSuperview() make.left.equalToSuperview().offset(36) make.right.lessThanOrEqualToSuperview().offset(-15) } } }