OOUISearchController.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // OOUISearchController.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/11/28.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. class OOUISearchController: UISearchController,UISearchBarDelegate {
  10. override init(searchResultsController: UIViewController?) {
  11. super.init(searchResultsController: searchResultsController)
  12. self.dimsBackgroundDuringPresentation = true
  13. //self.hidesNavigationBarDuringPresentation = false
  14. let attributesKey = [NSAttributedString.Key.foregroundColor:UIColor(hex: "#999999"),NSAttributedString.Key.font:UIFont.init(name: "PingFangSC-Regular", size: 14)!]
  15. UIBarButtonItem.appearance(whenContainedInInstancesOf:[UISearchBar.self]).setTitleTextAttributes(attributesKey, for: .normal)
  16. UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).title = "取消"
  17. let searchBar = self.searchBar
  18. searchBar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
  19. //tintColor
  20. //searchBar.tintColor = UIColor(hex: "#999999")
  21. //searchBar.barTintColor = UIColor(hex : "#F5F5F5")
  22. //searchBar.setPositionAdjustment(UIOffsetMake(50, 0), for: .search)
  23. //searchBar.searchFieldBackgroundPositionAdjustment = UIOffsetMake(50, 0)
  24. //searchBar.searchTextPositionAdjustment = UIOffsetMake(50, 0)
  25. //searchBar.placeholder = "请输入组织、人员或群组名称或字母"
  26. let textField = searchBar.value(forKey: "_searchField") as! UITextField
  27. textField.attributedPlaceholder = NSMutableAttributedString(string: "请输入组织、人员或群组名称或字母", attributes: attributesKey)
  28. textField.theme_textColor = ThemeColorPicker(keyPath: "Base.base_color")
  29. textField.font = UIFont(name: "PingFangSC-Regular", size: 14)
  30. //
  31. searchBar.setImage(O2ThemeManager.image(for: "Icon.search"), for: .search, state: .normal)
  32. searchBar.delegate = self
  33. }
  34. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  35. super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  36. }
  37. required init?(coder aDecoder: NSCoder) {
  38. fatalError("init(coder:) has not been implemented")
  39. }
  40. }