// // MCNavBarSearchView.swift // HCQuanfangtong // // Created by Apple on 2022/8/1. // Copyright © 2022 Jyp. All rights reserved. // import UIKit import RxSwift import RxCocoa class MCNavBarSearchView: MCNavBarView { /// 初始化方法 /// - Parameters: /// - placeholder: <#placeholder description#> /// - beginEditBlock: 开始编辑的方法 /// - endEditBlock: 搜索的方法 /// - tap: 点击事件 /// - style: <#style description#> init(placeholder: String?, beginEditBlock: (()->Void)?, endEditBlock: ((String?)->Void)?, tap: (()->Void)? = nil, style: MCNavBarStyle? = nil){ super.init(title: nil, subTitle: nil, style: style) self.searchBar = QFTSearchBar.init(frame: CGRect.zero) self.searchBar.contentend = endEditBlock self.searchBar.showKeyBoard = beginEditBlock if tap.isNotNil{ self.searchBar.toSearch = {isClear in if isClear{ endEditBlock?("") } else{ tap?() } } } self.searchBar.placeholder = placeholder self.searchBar.layer.cornerRadius = self.navStyle.styleForSearchHeight * 0.5 self.searchBar.setContentHuggingPriority(UILayoutPriority(rawValue: 240), for: .horizontal) self.contentView.addArrangedSubview(self.searchBar) self.searchBar.mas_makeConstraints { make in make?.height.offset()(self.navStyle.styleForSearchHeight) } self.resetConstraint() } override var type: MCNavBarType{ .search } //MARK: - Private Property private var searchBar: QFTSearchBar! //MARK: - Override MCNavBarDelegate override func setNavTitle(_ title: String?) { self.searchBar.text = title } override func setNavSubTitle(_ title: String?) { self.searchBar.placeholder = title } //MARK: - required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }