Adding Buttons Inside a UISearchBar

enter image description here

I want to add a button (bar) inside the UISearchbar, and the other outside the UISearch panel, as shown in the figure. Any help on this was appreciated.

Thanks in advance Naveen

+4
source share
3 answers

Edit:

As pointed out by @NicolasMiari in the comments:

This no longer works after iOS 7, as the bookmark button appears inside the line text box.


. ( ), " " ". :

[_searchBar setImage:[UIImage imageNamed:@"My-Custom-Image"] forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];

:

- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar {

    NSLog(@"click");
}
+14

UISearchBar - :

[self.searchDisplayController.searchBar setImage:[UIImage imageNamed:@"customImage.png"] forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];

,

[self.searchDisplayController.searchBar setPositionAdjustment:UIOffsetMake(-10, 0) forSearchBarIcon:UISearchBarIconBookmark];

" " " .

+4

Swift 4

var searchController: UISearchController = UISearchController(searchResultsController: nil)

override func viewDidLoad(){
  searchController.delegate = self 
  searchController.searchBar.delegate = self 
  searchController.searchBar.setImage(UIImage(named: "myImage"), for: UISearchBarIcon.bookmark, state: .normal)
...
extension ViewController: UISearchBarDelegate{

  func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar){
    print("click")
}
...
0
source

Source: https://habr.com/ru/post/1535761/


All Articles