lnafziger / Numberpad

iOS Custom Numberpad
MIT License
79 stars 28 forks source link

UISearchBar #2

Closed ewindso closed 11 years ago

ewindso commented 11 years ago

Hello there -- any tips on getting this to work with UISearchBar?

I've tried subclassing and making inputView readwrite... however it still shows default keyboard...

lnafziger commented 11 years ago

You need to set the inputView of the UITextField that the UISearchBar uses, but unfortunately Apple doesn't provide methods to access it directly. You can, however, search through the subviews of the search bar and set the inputView of the textField that it is using like this:

for (UIView *view in yourSearchBar.subviews) {
    if ([view isKindOfClass: [UITextField class]]) {
        UITextField *textField = (UITextField *)view;
        textField.inputView = [LNNumberpad defaultLNNumberpad];
        break;
    }
}