I have one UITextview in which user enter text. after that i take that text as a string and display it in another textview and want the words which are grammatically incorrect.
How to do that?
Use the UITextChecker class that's been available since ios 3.2: Apple Documentation
iOS system only provide spell checking while the user is inputting text. If the user choose to type in the wrong word or words, iOS cannot help. If you want to perform your own spell checking, you will have to include your own spell checking library.
GNU Aspell is a Free and Open Source spell checker designed to eventually replace Ispell. It can either be used as a library or as an independent spell checker.
Aspell Spell Checker on iPhone? was asked a few years ago here on SO. I am not sure if they ever got it working.
Use autocorrectionType property of UITextInputTraits protocol which is implemented by UITextView
#property(nonatomic) UITextAutocorrectionType autocorrectionType
Use it as below
To disable
myTxtview.autocorrectionType = UITextAutocorrectionTypeNo;
To enable
myTxtview.autocorrectionType = UITextAutocorrectionTypeYes;
In Apple Documentation
You can use Correction option under Text Input Traits in TextField Attributes using Interface Builder. It will take care of Valid English words.
Related
How can I check the spelling of a NSTextField using swift? I'm already using controlTextDidChange to validate the text. This solution seems to mention casting the first responder as a NSTextView but I'm not sure that is possible with swift using coercion. I know this would be easier if I changed to a NSTextView but if possible I'd like to avoid this.
This should help you out.
// Focus TextField
phraseTextField.becomeFirstResponder()
// Enable Continous Spelling
let textView: NSTextView = (self.window!.firstResponder as! NSTextView)
textView.continuousSpellCheckingEnabled = true
Adapted from: How do I enable spell checking within an NSTextField on Mac OS X?
In other situations, it may just work better to change NSTextFields to NSTextViews. Simply use a "Text View" (search NSTextView in the Object Library) and spell check will be on by default. NSTextFields simply do not support spell check in some cases, as best I can tell.
Also consult: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/#//apple_ref/doc/uid/20000373-SW55
I searched about autocapitalisation of a word in Swift on internet as well as on this site. I found the solutions but the solution is working for me. can you help me with this?
I have set capitalisation property of through text box property. screenshot is as follows:
I did the same thing through program also as follows, but nothing works for me:
txtabc.autocapitalizationType = UITextAutocapitalizationType.Words;
You have set your keyboard type as Name Phone Pad, which does not support auto-capitalization.
From UITextInputTraits Protocol Reference:
Some keyboard types do not support auto-capitalization. Specifically, this option is ignored if the value in the keyboardType property is set to UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, or UIKeyboardTypeNamePhonePad.
You could try with some other keyboard types and it should work properly.
Developing a iPhone application - where I want the 'Spell checker' functionality to be turned off when the application starts, firstly, is this possible? if yes, can someone help me with the code for the same?
Secondly, if this is possible, and what would happen, if the user pauses my application, and goes and starts another application, for instance sending a SMS where by default the iOS turns on the spell checker - when the user would switch back to my app, would the spell checker be turned on then?
Whether or not it’s enabled is a property of the text field, not of your application. It’s specified in the UITextInputTraits protocol; to disable autocorrection on a text field, you’d do this:
[myTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
You can do this by checking out the attributes when you select the UITextField or UITextView options
How would I go about italicizing a single word in an NSString which will be displayed in a UILabel? Specifically, I don't want all text to be italicized, just one word.
Thanks!
(Edited) I meant UILabel, not UITextField.
I don't think that what you are asking to do is possible (I'd be happy to be proven wrong). However, this library (https://github.com/facebook/three20/) is a popular way to achieve the same result in a UILabel (not text field) . The library works fairly well, but does have a lot of limitations, especially on edge conditions, and of course, it comes with associated overhead.
I'd encourage you to think about other ways of achieving the same user outcome. Can Placeholder text help? How about hints next to your text field?
Good luck.
A native UILabel does not support NSAttributedString which is what is normally used to display strings with formatting. You could try an output the text your self using Core Text but I would suggest checking out FontLabel or the three-20 project mentioned by #JJ Rohrer
Use NSAttributedString... Find controllers to draw NSAttributedString,since UILabel wont support NSAttributedString
Controller for NSAttributedString
Basically what I want to do is to use Cocoa's autocorrection feature on NSString.
E.g. [string autocorrect] would return what it text field shows in a popup
Is it possible?
As far as I know you can't, besides, why would you want it? If you want to auto correct a string then it would have to be inputted from somewhere, either by you or by the user. If it's by you then just run spell check before you input it in your code. If the user inputs it, just enable it in the text field using something like:
textfield.autocorrectionType = UITextAutocorrectionTypeYes;
This is a very old post, but now you can use UITextChecker to do this. There's a nice post about it on NSHipster: http://nshipster.com/uitextchecker/