LoginSignup
5
5

More than 5 years have passed since last update.

【Swift】UISearchBarのtextField内にボタンを設置する

Last updated at Posted at 2016-11-14

以下の画像のようにUISearchBar、textField内の一番右に任意のボタンを追加する方法。

スクリーンショット 2016-11-15 8.25.29.png

ここには本来ブックマークボタンが表示されますので、このブックマークボタンを表示させて、任意の画像に置き換えるという形を取ります。

コード

// ブックマークボタンを表示させる
searchController.searchBar.showsBookmarkButton = true

// ブックマークボタンに任意の画像を設定
searchController.searchBar.setImage(UIImage(named:"wood.ico"), for: .bookmark, state: .normal)


func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) {

    print("このボタンを押した時の処理")

}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5