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/
Related
So I have 2 apps. One is a sensors app (built with XCode) that records data (text) with hardware wireless sensors. The other is a checklist/reference manual (built with Titaniam Appcelerator). Using custom URL schemes, they can instantiate each other.
What I am trying to do is paste any text data the sensors app copies to the clipboard into a text field in the reference manual app. I have a UIWebview showing html pages (the checklist) with a text box displayed now. To demo the capability, I have to touch the field and select paste. I was thinking that javascript might work, but all my research poo poo's that idea. Any thoughts about how to grab the text that is on the clipboard and display it programmatically in the reference manual app without having to touch the field and select paste?
Should I even be looking at the clipboard or should I be looking into modifying the custom URL scheme to pass data that way instead?
To get the text from the clipboard:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *string = pasteboard.string;
if (string) {
// Do something
}
For more funcional communication between apps, take a look at URL Schemes.
So, I figured out a way to pass the data in the url with this tutorial. At the bottom it describes how to pass data after you set up the URL id for each app. Hope this helps someone.
Pasting in Swift
Get the pasteboard string with UIPasteboard.generalPasteboard().string.
The string is optional, so it must be unwrapped before being used.
if let pasteboardString = UIPasteboard.generalPasteboard().string {
// use the string, for example:
myTextView.insertText(pasteboardString)
}
Note
The original question is asking for something more complex than this. However, most people come here based on the question title rather than question content, so that I what I am answering here.
i want to use UILabel with link.
for that i am using IFTweetLabel which is finding any link and showing a line under it and it is clickable.
but if a string is big then only first line is getting hyperlink instead of complete URL.
as an issue with https://github.com/clawoo/IFTweetLabel/issues/3.
so is there any other option for it , or other library ?
First you have to import RegexKitLite framework. Go through this link. Surely this will help you. It gives same thing as you want.
http://furbo.org/stuff/FancyLabel_1.0.zip
First thing I would like to suggest is
Use UITextView with editing property as NO and it will automatically detect all the links separately similar like the one you need.
textview.editable = NO;
textview.dataDetectorTypes = UIDataDetectorTypeAll;
If you still want to go with UILabel then
You can achieve this by using NSArrtibutedStrings — but I would recommend to use some wrapper around this C-functions. I like OHAttributedLabel.
The demo included shows exactly, how hyperlinks can be handled.
You should give a try to three20 project.
what is the reason for not using UITextView..there is link detection property for UITextView.Your app is not going to get rejected
I would like to be able to format a URL in my UITextField nicely. So say the text of the UITextField is
textField.text = #"Hi this is a page for my website http://www.mywebsite.com";
I would like it to automatically underline this mark it as a hyperlink and when a user taps on the link it opens up the site. This is similar to any twitter client that you have out there (tweetdeck, tweetbot, etc). How do I do this the easy way?
You can use a UITextView instead and set the dataDetectorTypes property to the types of links you want to be able to handle.
hey this is really simple, you can set the UITextFiled to detect Links, like so:
myTextView.dataDetectorTypes = UIDataDetectorTypeAll
check out my tutorial on this at my site for more info
http://www.sdkboy.com
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.
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