Подтвердить что ты не робот

Отключить предложения ярлыков клавиатуры UITextField

Есть ли простой способ удалить подсказки клавиатуры из UITextField?

Можно удалить коррекцию текста с помощью [textField setAutocorrectionType:UITextAutocorrectionTypeNo];, однако это не влияет на ярлыки.

Влияет на sharedMenuController и не сквозит это.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    [UIMenuController sharedMenuController].menuVisible = NO;
    return  NO;
}

enter image description here

4b9b3361

Ответ 1

Решил это, внедрив метод UITextFieldDelegate и вручную установив свойство текста UITextField.

По умолчанию в симуляторе вы можете проверить это поведение, набрав "omw", который должен предлагать "На моем пути!". Следующий код блокирует это. Примечание. Это также отключает автоматическую коррекцию и проверяет правописание, что было в моем случае.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    // Pass through backspace and character input
    if (range.length > 0 && [string isEqualToString:@""]) {
        textField.text = [textField.text substringToIndex:textField.text.length-1];
    } else {
        textField.text = [textField.text stringByAppendingString:string];
    }
    // Return NO to override default UITextField behaviors
    return NO;
}

Ответ 3

Используйте это только

  textField.autocorrectionType = UITextAutocorrectionTypeNo;

Ответ 4

textField.autocorrectionType = .No

Ответ 5

Swift 3.x или выше:

textField.autocorrectionType = .no

Ответ 6

UITextField* f = [[UITextField alloc] init];
f.autocorrectionType = UITextAutocorrectionTypeNo;

Ответ 7

Вышеупомянутый ответ может не работать с ситуацией cut/copy/paste. Например, при разрезании и вставке текста в UITextField результат не соответствует функциональности по умолчанию.

Ниже приведен аналогичный подход:

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

NSString *textFieldNewText = [textField.text stringByReplacingCharactersInRange:range withString:string];

    if ([string isEqualToString:@""]) {
        // return when something is being cut
        return YES;
    }
    else
    {
        //set text field text
        textField.text=textFieldNewText;
        range.location=range.location+[string length];
        range.length=0;
        [self selectTextInTextField:textField range:range];
    }
    return NO;
}


//for handling cursor position when setting textfield text through code
- (void)selectTextInTextField:(UITextField *)textField range:(NSRange)range {

    UITextPosition *from = [textField positionFromPosition:[textField beginningOfDocument] offset:range.location];
    UITextPosition *to = [textField positionFromPosition:from offset:range.length];
    [textField setSelectedTextRange:[textField textRangeFromPosition:from toPosition:to]];
}

Ответ 8

Использовать AutocorrectionType:

[mailTextField setAutocorrectionType: UITextAutocorrectionTypeNo];