SoFunction
Updated on 2025-04-12

Implementation method of using UISearchBar control to limit the number of input words in iOS

I won’t say much nonsense, I will just introduce the key code to you. The specific code is as follows:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText // called when text changes (including clear)
{
if ( > IMPUT_MAX){
 = [ substringToIndex:15];
}
}

Okay, that's the end, I hope it will be helpful to everyone. If you have any questions, please leave me a message. The editor will reply to everyone in time. Thank you very much for your support for my website on this page!