Disable Spell Check in iOSTextField

Can spell check be disabled in an iOSTextField in an iOS app?

If the iOSTextField is used to enter a URL, spell check is constantly in the way.

[quote=318977:@Harold Halbleib]Can spell check be disabled in an iOSTextField in an iOS app?

If the iOSTextField is used to enter a URL, spell check is constantly in the way.[/quote]

the answer to the question you asked is… YES, spell check can be disabled in an iOS app…
The question you should ask, is
How do I disable spellcheck in Xojo for iOS?

[quote=318977:@Harold Halbleib]Can spell check be disabled in an iOSTextField in an iOS app?

If the iOSTextField is used to enter a URL, spell check is constantly in the way.[/quote]

If you switch to using an iOSLibTextField from @Ulrich Bogun available on Git then you can turn off spell checking with:

me.spellCheckingType = AppleTextField.UITextSpellCheckingType.No

And I also suggest you might want to do this:

me.autoCorrectionType = AppleTextField.UITextAutocorrectionType.No

Declare sub setAutocapitalizationType_ lib "UIKit.framework" selector "setAutocapitalizationType:" (obj_id as ptr, value as boolean) setAutocapitalizationType_(textfield.handle, false)

I would assume the same works for

  • autocapitalizationType
  • spellCheckingType
  • isSecureTextEntry
  • autocorrectiontype

The last two are boolean (although Xcode wants .yes or .no for SpellCheck , but true or false for isSecureTextEntry (ie. Password)
and autoCap has a whole list of enums connected to it…

iOSLib is outdated. Better use GitHub - UBogun/Xojo-AppleLib: A library extending Xojo‘s macOs and iOS features – 64 bit and new framework compatible. if you want to.

Jrmie Leroy’s solution works fine to turn off capitalization when pasted into the iosView Open event.

Declare sub setAutocapitalizationType_ lib “UIKit.framework” selector “setAutocapitalizationType:” (obj_id as ptr, value as boolean)
setAutocapitalizationType_(textfield.handle, false)

Any idea how to create a similar declare to turn of autocorrect. The following code compiles, but doesn’t work.

Declare sub setAutocorrectionType lib “UIKit.framework” selector “setAutocorrectionType:” (obj_id as ptr, value as boolean)
setAutocorrectionType(WorkbookURLEdit.handle, false)

declare sub autocorrectionType_ lib "UIKit.framework" selector "setAutocorrectionType:" (obj_id as ptr, autocorrectionType as Integer) autocorrectionType_(textfield.Handle, 1)

The integer value can be one of the following:
0: default
1: no
2: yes

Hi Jeremie, I’m never great with Declares; how do I implement the declare you have shown into a project? I’d like all textfields to be non capitalizing and non autocorrect.

Hi Boudewijn,

I too struggled for many years with declares, and finally got an enlightenment 3 years ago :slight_smile:

First create a subclass of iOSTextField:

  • Xojo Insert Menu > Class
  • Define the name of your TextField Subclass, ie: MyTextfieldSubclass
  • Set Super to iOSTextField

Then implement the Open event of your Textfield subclass and add the following code:

Declare sub setAutocorrectionType_ lib "UIKit.framework" selector "setAutocorrectionType:" (obj_id as ptr, value as Integer)
Declare Sub setAutocapitalizationType_ Lib "UIKit.framework" selector "setAutocapitalizationType:" (obj_id As ptr, value As Integer)

setAutocorrectionType_(self.Handle, 1)
setAutocapitalizationType_(self.Handle, 0)

RaiseEvent Open

Finally, Add a new Event Definition to the class and name it Open

In your project, whenever you need a textfield with no Autocorrect and no Autocapitalization, use your TextField subclass.

1 Like

Works like a charm! Thanks!

1 Like