title: 【UISearchController / UISearchBar】How to add tap gesture to search icon?
body: <p>I am currently <code>using UISearchController</code> in my app.</p>
  <p>I'd like to execute a process(NOT search process) using text entered in textField when leftView's search icon is tapped.</p>
  <p>Therefore, I attempted to add tap gesture(or long press gesture) to the icon <code>using UIGestureRecognizer and UILongPressGestureRecognizer</code>, and it didn't make anything happen.</p>
  <p><strong>Question 1:</strong><br />
  <code>Does the icon originally not trigger any actions when tapped? (It doesn't even call &quot;searchBarSearchButtonClicked&quot; function when tapped.)</code></p>
  <p><strong>Question 2:</strong><br />
  <code>Is there any way to use the icon like clickable button, and trigger a specific action when tapped?</code></p>
  <p>For your reference, my code and screen image are below.<br />
  If you have some additional information you need, please let me know.<br />
  Thank you in advance.</p>
  <p><strong>Update: Bookmark button didn't work as expected...</strong><br />
  I attempted for bookmark button.  However, it didn't work as expected because it was hidden underneath a clear icon when entering text.<br />
  It would be ideal if bookmark button keeps being shown even though text is entered.</p>
  <h2>target icon image</h2>
  <p><img src="https://i.stack.imgur.com/6Wui2.png" alt="target icon image" /></p>
  <p><strong>Properties:</strong></p>
  <pre><code>let searchController = UISearchController(searchResultsController: nil)
  var keyword = &quot;&quot;
  </code></pre>
  <p><strong>setupSearchController:</strong><br />
  I changed the color and image of search icon in the function below.</p>
  <pre><code>private func setupSearchController() {
      navigationItem.searchController = searchController
      navigationItem.hidesSearchBarWhenScrolling = true
      definesPresentationContext = true
  
      searchController.delegate = self
      searchController.obscuresBackgroundDuringPresentation = false
      searchController.searchResultsUpdater = self
  
      searchController.searchBar.delegate = self
      searchController.searchBar.placeholder = &quot;Search channels&quot;
  
      // search icon settings
      searchController.searchBar.searchTextField.leftView?.tintColor = .link
      searchController.searchBar.setImage(UIImage(systemName: &quot;globe&quot;), for: .search, state: .normal)
  }
  </code></pre>
  <p><strong>setupTranslateButton:</strong><br />
  I attempted for two ways, <strong>UITapGestureRecognizer</strong> and <strong>UILongPressGestureRecognizer</strong>, both of which didn't make anything happen.</p>
  <pre><code>// UITapGestureRecognizer version
  private func setupTranslateButton() {
      let transButton = searchController.searchBar.searchTextField.leftView!
  
      let tap = UITapGestureRecognizer(target: self, action: #selector(translateKeyword))
          transButton.addGestureRecognizer(tap)
      searchController.searchBar.searchTextField.addSubview(transButton)
  }
  
  // UILongPressGestureRecognizer version
  private func setupTranslateButton() {
      let transButton = searchController.searchBar.searchTextField.leftView!
  
      let tap = UILongPressGestureRecognizer(target: self, action: #selector(translateKeyword))
      tap.minimumPressDuration = 0
      transButton.addGestureRecognizer(tap)
  } 
  </code></pre>
  <p><strong>translateKeyword:</strong><br />
  I'd like the following function called when tap gesture is successfully triggered.</p>
  <pre><code>@objc func translateKeyword(_ sender: UILongPressGestureRecognizer) {
  
      print(&quot;Translate button is clicked...&quot;)
  
      // keyword string should exist by the process executed in &quot;updateSearchResults&quot; function 
      if keyword.isEmpty {
          print(&quot;Keyword is empty&quot;)
          return
      }
  
      // The following process is here...
  }
  </code></pre>
  <p><strong>updateSearchResults:</strong><br />
  All texts are put into keyword variable every time it's entered in textField.</p>
  <pre><code>func updateSearchResults(for searchController: UISearchController) {
          
      print(&quot;updateSearchResults&quot;)
         
      guard let inputKeyword = searchController.searchBar.text, !inputKeyword.isEmpty else {
          print(&quot;Keyword is not entered...&quot;)
          return
      }
          
      keyword = inputKeyword
  }
  </code></pre>