2024-03-22 11:54:23 +08:00
|
|
|
//
|
|
|
|
// HomeSearchNavView.swift
|
|
|
|
// yinmeng-ios
|
|
|
|
//
|
2024-03-23 20:47:19 +08:00
|
|
|
// Created by yinmeng on 2024/3/21.
|
2024-03-22 11:54:23 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
|
|
|
|
typealias ClickSearchBlcok = (_ type:Int)->Void
|
|
|
|
|
|
|
|
class HomeSearchNavView: UIView {
|
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
setUILayout()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
private func setUILayout(){
|
|
|
|
addSubview(leftArrowBtn)
|
|
|
|
addSubview(bgSearchView)
|
|
|
|
addSubview(searchBtn)
|
|
|
|
bgSearchView.addSubview(searchIconView)
|
|
|
|
bgSearchView.addSubview(textField)
|
|
|
|
|
|
|
|
leftArrowBtn.snp.makeConstraints { make in
|
|
|
|
make.width.height.equalTo(UIDevice.scaleWidth(width: 22))
|
|
|
|
make.leading.equalTo(UIDevice.scaleWidth(width: 8))
|
|
|
|
make.centerY.equalTo(bgSearchView)
|
|
|
|
}
|
|
|
|
bgSearchView.snp.makeConstraints { make in
|
|
|
|
make.height.equalTo(UIDevice.scaleWidth(width: 30))
|
|
|
|
make.leading.equalTo(leftArrowBtn.snp.trailing).offset((UIDevice.scaleWidth(width: 5)))
|
|
|
|
make.trailing.equalTo(searchBtn.snp.leading).offset(-UIDevice.scaleWidth(width: 13))
|
|
|
|
make.top.equalTo(UIDevice.scaleWidth(width: StatusBarHeight + 10))
|
|
|
|
}
|
|
|
|
searchBtn.snp.makeConstraints { make in
|
|
|
|
make.trailing.equalTo(-UIDevice.scaleWidth(width: 15))
|
|
|
|
make.centerY.equalTo(bgSearchView)
|
|
|
|
make.height.equalTo(UIDevice.scaleWidth(width: 30))
|
|
|
|
|
|
|
|
}
|
|
|
|
searchIconView.snp.makeConstraints { make in
|
|
|
|
make.width.height.equalTo(UIDevice.scaleWidth(width: 28))
|
|
|
|
make.centerY.equalTo(bgSearchView)
|
|
|
|
make.leading.equalTo(UIDevice.scaleWidth(width: 9))
|
|
|
|
}
|
|
|
|
textField.snp.makeConstraints { make in
|
|
|
|
make.leading.equalTo(searchIconView.snp.trailing).offset((UIDevice.scaleWidth(width: 0)))
|
|
|
|
make.trailing.top.bottom.equalTo(bgSearchView)
|
|
|
|
}
|
|
|
|
leftArrowBtn.addTarget(self, action: #selector(leftArroAction), for: .touchUpInside)
|
|
|
|
searchBtn.addTarget(self, action: #selector(searchBtnAction), for: .touchUpInside)
|
|
|
|
}
|
|
|
|
@objc func leftArroAction(){
|
|
|
|
if let clickSearchBlcok = self.clickSearchBlcok{
|
|
|
|
clickSearchBlcok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@objc func searchBtnAction(){
|
|
|
|
textField.resignFirstResponder()
|
|
|
|
if let clickSearchBlcok = self.clickSearchBlcok{
|
|
|
|
clickSearchBlcok(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//MARK: - 懒加载
|
|
|
|
var clickSearchBlcok:ClickSearchBlcok?
|
|
|
|
private lazy var leftArrowBtn:UIButton = {
|
|
|
|
let _leftArrowBtn = UIButton.getCustomBtn(image: UIImage(named: "yin_left_black_arrow"))
|
|
|
|
_leftArrowBtn.setBtnClickRadius = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
|
|
|
|
return _leftArrowBtn
|
|
|
|
}()
|
|
|
|
private lazy var bgSearchView:UIView = {
|
|
|
|
let _bgSearchView = UIView()
|
|
|
|
_bgSearchView.backgroundColor = .white
|
|
|
|
_bgSearchView.layer.cornerRadius = UIDevice.scaleWidth(width: 30)/2
|
|
|
|
_bgSearchView.layer.masksToBounds = true
|
|
|
|
|
|
|
|
return _bgSearchView
|
|
|
|
}()
|
|
|
|
private lazy var searchIconView:UIImageView = {
|
|
|
|
let _searchIconView = UIImageView()
|
|
|
|
_searchIconView.isUserInteractionEnabled = true
|
|
|
|
|
|
|
|
_searchIconView.image = UIImage(named: "yin_search_vc_iocn")
|
|
|
|
return _searchIconView
|
|
|
|
}()
|
|
|
|
lazy var textField:UITextField = {
|
|
|
|
let _textField = UITextField()
|
|
|
|
_textField.layer.cornerRadius = UIDevice.scaleWidth(width: 30)/2
|
|
|
|
_textField.layer.masksToBounds = true
|
|
|
|
_textField.tintColor = ThemeColor(hexStr: "#878B9C")
|
|
|
|
_textField.textColor = ThemeColor(hexStr: "#282828")
|
|
|
|
_textField.backgroundColor = .clear
|
|
|
|
_textField.font = UIFont.getScaleFont(ofSize: 13, weight: .regular)
|
|
|
|
let att = NSAttributedString(string: "搜索昵称/ID/房间名",attributes: [.font:UIFont.getScaleFont(ofSize: 13, weight: .regular),.foregroundColor:ThemeColor(hexStr: "#878B9C")])
|
|
|
|
_textField.attributedPlaceholder = att
|
|
|
|
_textField.clearButtonMode = .whileEditing
|
|
|
|
_textField.returnKeyType = .search
|
|
|
|
_textField.enablesReturnKeyAutomatically = true
|
|
|
|
return _textField
|
|
|
|
}()
|
|
|
|
private lazy var searchBtn:UIButton = {
|
|
|
|
let _searchBtn = UIButton.getCustomBtn(text: "搜索",font: UIFont.getScaleFont(ofSize: 16, weight: .medium),color: ThemeColor(hexStr: "#878B9C"))
|
|
|
|
_searchBtn.setBtnClickRadius = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
|
|
|
|
|
|
|
|
return _searchBtn
|
|
|
|
}()
|
|
|
|
}
|