Thursday, October 6, 2011

Adding links to a textview

Ok, so, we're getting close to the release. I added the quiz numbers by level yesterday. Now, things I still need to do:

1) Add links to my web set, JLPT web set
3) Submit the app
4) Disable the next question button when question is asked
5) Get rid of the back button on NextLevel
6) Splash

I'm having trouble motivating myself. It's not like what I'm doing right now is hard. I've always enjoyed programming. It just seems tough to get going. Once I get into it, I should start enjoying it more. The key is to enjoy the learning process.

Btw, I've come across Stanfords iTunes course in iOS programming. It's really great - gives you a great background. I wish I had found it sooner.

Ok, so, how to add a link to the display? Learning. Calm. Fun.

Well, SO has some insight:



textView.text = @"Some text with link in it : http://http://stackoverflow.com";
textView.dataDetectorTypes = UIDataDetectorTypeLink;


So, this looks pretty simple. Let's try it.

Well, he wants UITextview, I assume because of the name. Why would that be?

Well, this looks pretty good:

Detecting phone numbers and links in an iPhone application
Q: How do I detect phone numbers and links in an iPhone application?

A: How do I detect phone numbers and links in an iPhone application?

// http://developer.apple.com/library/ios/#qa/qa1495/_index.htmlAs of iPhone OS 3.0, text views and web views support the detection of phone numbers, email addresses, and HTTP links. iPhone OS 3.0 scans for these types of data, highlights them when found, and renders them into clickable URLs as shown in Figure 1. You can detect phone numbers and links programmatically or by using Interface Builder 3.1.2 or later.
Figure 1 Detecting phone numbers, email addresses, and HTTP links in a text view



This looks pretty good:

Using Interface Builder

Follow these steps to detect phone numbers and links using Interface Builder 3.1.2 or later:

Open the Nib file containing your web view or text view in Interface Builder.

Select your view, then choose Tools > Attributes Inspector. The Attributes Inspector contains the Detect Phone Numbers and Detect Links options, which respectively turn on phone numbers detection and links (email and URLs) detection.

Check one of these options or both of them according to your needs as shown in Figure 2.



Well, what happens when I do that is the keyboard pops up instead of take me to a hyperlink. I think I need to mark it as non-editable.

Ok, good. That works. What have we learned? To create a link in the IB, use UITextView, and mark it is non-editable.

Ok, well, I really just need to acknowledgement url. I can leave it that for now.

No comments:

Post a Comment