81 lines
2.1 KiB
Swift
81 lines
2.1 KiB
Swift
//
|
|
// SPSearchInputView.swift
|
|
// Thimra
|
|
//
|
|
// Created by 曾觉新 on 2025/4/17.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPSearchInputView: UIView {
|
|
|
|
override var intrinsicContentSize: CGSize {
|
|
return CGSize(width: kSPScreenWidth, height: 36)
|
|
}
|
|
|
|
var placeholder: String? {
|
|
didSet {
|
|
textField.sp_placeholder = placeholder
|
|
}
|
|
}
|
|
|
|
var textDidChange: ((_ text: String) -> Void)?
|
|
|
|
//MARK: UI属性
|
|
private lazy var iconImageView: UIImageView = {
|
|
let imageView = UIImageView(image: UIImage(named: "search_icon_02"))
|
|
imageView.setContentHuggingPriority(.required, for: .horizontal)
|
|
imageView.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
return imageView
|
|
}()
|
|
|
|
private(set) lazy var textField: SPTextField = {
|
|
let textField = SPTextField()
|
|
textField.font = .fontMedium(ofSize: 14)
|
|
textField.sp_placeholderFont = .fontRegular(ofSize: 14)
|
|
textField.returnKeyType = .search
|
|
textField.textDidChange = { [weak self] text in
|
|
self?.textDidChange?(text)
|
|
}
|
|
return textField
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
layer.cornerRadius = 8
|
|
layer.masksToBounds = true
|
|
backgroundColor = .colorFFFFFF(alpha: 0.2)
|
|
|
|
setContentHuggingPriority(.required, for: .vertical)
|
|
setContentCompressionResistancePriority(.required, for: .vertical)
|
|
|
|
_setupUI()
|
|
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension SPSearchInputView {
|
|
|
|
private func _setupUI() {
|
|
addSubview(iconImageView)
|
|
addSubview(textField)
|
|
|
|
iconImageView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(16)
|
|
make.centerY.equalToSuperview()
|
|
}
|
|
|
|
textField.snp.makeConstraints { make in
|
|
make.top.bottom.equalToSuperview()
|
|
make.left.equalTo(iconImageView.snp.right).offset(8)
|
|
make.right.equalToSuperview().offset(-15)
|
|
}
|
|
}
|
|
|
|
}
|