detecting URL and format it in UITextField - iphone

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

Related

login form in iphone native application

I am trying to do the login form I have created two uitextfields for username ,password and one uibutton for login. when I enter password in password textfield I want to display all the text as '*' or any special characters like in the following images
Is there any default ways in sdk to do this or we have to do it logically if any give me some sample codes? Thanks in advance
The UITextInputField conforms to the UITextInputTraits protocol, which means you can use the following to tell it to display "*"s:
[passwordTextInputField setSecureTextEntry:YES];
Open you NIB-File in Interface-Builder, mark your UITextField and open the Inspector (Tools > Inspector). In the very left Tab (Attributes) set the value of "Secure" to TRUE.
See the Screenshot below:
Programmaticaly you can use the following line of Code:
password.secureTextEntry = TRUE
Where password is your UITextField.
You can use [myTextField setSecureTextEntry:YES] which is part of the UITextInputTraits protocol whom UITextField adhere.
Don't know of a "free" way to change the secure character, though.

how to place url string

hi i am new to iphone. what i need is i have to place a url as a string eg:http://stackoverflow.com by selecting the string it self open in a web brosewr how can i done this. post some code or link thank u.
Add a textView control onto your NIB file. Put whatever content (you mention 5 lines of text) you want in here. In the properties for this control, under the "Detection" section, click "Links". Then, any URL links in this text will be automatically highlighted in blue, and when your users tap on it they will be taken to that URL in the browser.
Your question could have been a little clearer - I only got what you were after because of your previous comment on puckipedia's answer...
To open A url use (in Objective-C)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URLHere]];

How do I know if text contains URL links (UIWebView)

I have some text which might or might not contain web URLs, phone numbers, email links etc. which UIWebView automatically detects as hotspots.
Question: I want to show this text in UIWebView ONLY when there are one or more hotspots, but as plain text if it doesn't. So how can I detect this in code?
Additional Info: JavaScript code below tells how many ... links there are. This does NOT count how many other "link" items there are. For example "Link to www.yle.fi" contains one link according to UIWebView, but zero according to JavaScript:
NSString *s = [webView stringByEvaluatingJavaScriptFromString:
#"document.links.length"];
Still no answer to the question how to ask UIWebView how many links it has found...
You can use several regular expressions and check if the text matches those of URL/phone number/email addresses.
However, if your intention is simply let the user open a link, the UITextView is suffice.
Check the dataDetectorTypes property.

Best approach for simple link within UITextView

I am creating a dictionary lookup application. The user selects a word from a UITableView and the app displays the definition. In some cases the word will be similar to another word, so I want to display "See Also:" followed by a list of similar words that when touched, bring up another definition.
In searching here on links within UITextViews, most of the answers involve linking out to the web, which is not really what I need. I simply want to get control when the user touches a word so that I can change the view.
Is UIWebView the only way to do this, or did I miss something obvious in the SDK? Also, I'd prefer to stay within the native SDK and not go the three20 route.
Thanks!
I would use another UITableView to make this work. Your list of similar words will probably be in NSArray format already, so it would be pretty easy to set up another UITableView instead of a UITextView to display the list, and given that you already have this code working for the main UITableView, you already know how to make them clickable!
A UIWebView will be the only thing that suits here I'm afraid. Data detectors are the only way to link inside of a UITextView, and they will only respond to the appropriate data types (Phone number, web page, address)...
Links can be done the normal way:
<a href='http://someotherword'>someotherword</a>
Setup the webviewdelegate to snag any link requests (and prevent them from being opened in the browser) so that you can open them in your own handler:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
{
if(navigationType == UIWebViewNavigationTypeOther) return YES; // Allow direct loading
NSString *myWord = [[request URL] host];
// do something with myWord... say open another word
return NO; // Don't let the browser actually perform this navigation
}

Autocorrect NSString on iPhone

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/