MCNavBarSearchView.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // MCNavBarSearchView.swift
  3. // HCQuanfangtong
  4. //
  5. // Created by Apple on 2022/8/1.
  6. // Copyright © 2022 Jyp. All rights reserved.
  7. //
  8. import UIKit
  9. import RxSwift
  10. import RxCocoa
  11. class MCNavBarSearchView: MCNavBarView {
  12. /// 初始化方法
  13. /// - Parameters:
  14. /// - placeholder: <#placeholder description#>
  15. /// - beginEditBlock: 开始编辑的方法
  16. /// - endEditBlock: 搜索的方法
  17. /// - tap: 点击事件
  18. /// - style: <#style description#>
  19. init(placeholder: String?, beginEditBlock: (()->Void)?, endEditBlock: ((String?)->Void)?, tap: (()->Void)? = nil, style: MCNavBarStyle? = nil){
  20. super.init(title: nil, subTitle: nil, style: style)
  21. self.searchBar = QFTSearchBar.init(frame: CGRect.zero)
  22. self.searchBar.contentend = endEditBlock
  23. self.searchBar.showKeyBoard = beginEditBlock
  24. if tap.isNotNil{
  25. self.searchBar.toSearch = {isClear in
  26. if isClear{
  27. endEditBlock?("")
  28. }
  29. else{
  30. tap?()
  31. }
  32. }
  33. }
  34. self.searchBar.placeholder = placeholder
  35. self.searchBar.layer.cornerRadius = self.navStyle.styleForSearchHeight * 0.5
  36. self.searchBar.setContentHuggingPriority(UILayoutPriority(rawValue: 240), for: .horizontal)
  37. self.contentView.addArrangedSubview(self.searchBar)
  38. self.searchBar.mas_makeConstraints { make in
  39. make?.height.offset()(self.navStyle.styleForSearchHeight)
  40. }
  41. self.resetConstraint()
  42. }
  43. override var type: MCNavBarType{
  44. .search
  45. }
  46. //MARK: - Private Property
  47. private var searchBar: QFTSearchBar!
  48. //MARK: - Override MCNavBarDelegate
  49. override func setNavTitle(_ title: String?) {
  50. self.searchBar.text = title
  51. }
  52. override func setNavSubTitle(_ title: String?) {
  53. self.searchBar.placeholder = title
  54. }
  55. //MARK: -
  56. required init?(coder: NSCoder) {
  57. fatalError("init(coder:) has not been implemented")
  58. }
  59. }