102 lines
2.6 KiB
Swift
102 lines
2.6 KiB
Swift
//
|
|
// VPHomeSearchButton.swift
|
|
// Veloria
|
|
//
|
|
// Created by Veloria on 2025/5/22.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class VPHomeSearchButton: UIControl {
|
|
|
|
var marqueeArr: [VPShortModel] = [] {
|
|
didSet {
|
|
marqueeView.reloadData()
|
|
}
|
|
}
|
|
|
|
private lazy var currentIndex = 0
|
|
|
|
private lazy var iconImageView: UIImageView = {
|
|
let imageView = UIImageView(image: UIImage(named: "search_icon_01"))
|
|
return imageView
|
|
}()
|
|
|
|
|
|
private lazy var marqueeView: VPMarqueeView = {
|
|
let view = VPMarqueeView()
|
|
view.dataSource = self
|
|
view.start()
|
|
return view
|
|
}()
|
|
|
|
private lazy var textLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 14)
|
|
label.textColor = .colorFFFFFF(alpha: 0.3)
|
|
label.text = "kSearchPlaceholderText1".localized
|
|
return label
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
vp_setupUI()
|
|
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension VPHomeSearchButton {
|
|
|
|
private func vp_setupUI() {
|
|
layer.cornerRadius = 6
|
|
layer.masksToBounds = true
|
|
layer.borderWidth = 0.7
|
|
layer.borderColor = UIColor.colorFFFFFF(alpha: 0.1).cgColor
|
|
backgroundColor = UIColor.colorFFFFFF(alpha: 0.05)
|
|
|
|
|
|
addSubview(iconImageView)
|
|
addSubview(marqueeView)
|
|
|
|
|
|
iconImageView.snp.makeConstraints { make in
|
|
make.centerY.equalToSuperview()
|
|
make.left.equalToSuperview().offset(10)
|
|
}
|
|
|
|
marqueeView.snp.makeConstraints { make in
|
|
make.left.equalTo(iconImageView.snp.right).offset(6)
|
|
make.top.bottom.equalToSuperview()
|
|
make.right.equalToSuperview().offset(-10)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension VPHomeSearchButton: VPMarqueeViewDataSource {
|
|
func numberOfItems(_ marqueeView: VPMarqueeView) -> Int {
|
|
return marqueeArr.count == 0 ? 1 : marqueeArr.count
|
|
}
|
|
|
|
func marqueeView(_ marqueeView: VPMarqueeView, cellForItemAt index: Int) -> NSAttributedString {
|
|
var text: String
|
|
if marqueeArr.count == 0 {
|
|
text = "kSearchPlaceholderText1".localized
|
|
} else {
|
|
text = marqueeArr[index].name ?? ""
|
|
}
|
|
|
|
let string = NSMutableAttributedString(string: text)
|
|
string.font = .fontRegular(ofSize: 14)
|
|
string.color = .colorFFFFFF(alpha: 0.3)
|
|
|
|
return string
|
|
}
|
|
}
|