UISearchBar常见问题

UISearchBar

1.UISearchBar右边设置语音搜索按钮

self.mySearchController.searchBar.showsBookmarkButton = YES;
[self.mySearchController.searchBar setImage:[UIImage imageNamed:@"VoiceSearchStartBtn"] forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];

- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar {
    [self startListenWrite];
}
    

2.UISearchBar取消按钮,自定义文字

[self.mySearchController.searchBar setPlaceholder:@"请输入姓名汉字/拼音字母"]; self.mySearchController.searchBar.showsCancelButton = YES;
for(UIView *view in  [[[self.mySearchController.searchBar subviews] objectAtIndex:0] subviews]) {
    if([view isKindOfClass:[UIButton class]]) {
         UIButton * cancel =(UIButton *)view;
         [cancel setTitle:@"取消" forState:UIControlStateNormal];
    }
}

你可能感兴趣的:(UISearchBar常见问题)