showing hyperlink in iphone - iphone

I have a field in sqlite db which has multiple links inside it separted by comma. I displayed one link by placing it in a label and placing an invisible button over it and capturing the click of the button.Is there any other way to show these hyper links as the number of links in the field may change.

Use UITextView which automatically detects phone numbers, http links, and so on, if its dataDetectorTypes property is set properly to a required UIDataDetectorTypes value.

Related

How make NSTextView not selectable, but allow to select links

So I have NSTextView with attributed string which contain links from html markup. I want to make links clickable, but other text don't.
Delegate method which apple propose
textView:willChangeSelectionFromCharacterRanges:toCharacterRanges:
(in topic https://developer.apple.com/documentation/appkit/nstextview/1449297-selectable)
is not working as I want, I can only remove selection after it already has been selected
And property isSelectable block any mouse events, so link are not clickable either

Scrollable view with text and ability to do something when specific phrase is tapped

I am trying to implement a view which will load text from sqlite database (every sentence in a text will have unique tag in database) and will allow to execute some code while sentence is clicked (on-click executed method should then scroll clicked sentence to the center of the screen and change it's color/background color/font size to emphasize it)
Is it possible without using webview and js/js-native bridge? Which approach should be taken to implement such a view? Any help and comments highly appreciated!
Hmm, you could also considering using NSAttributedString together the Core Text Framework and attribute each sentence and attach some extra info about. Next you lookup the attribute below the tap position of the view. Once you have that you can retrieve the extra info again and do whatever you want with the tap.
After the tap you could then alter the properties of that part of the text. E.g. different font colour etc.
This tutorial on the internet looked interesting:
http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text

Adding hyperlink to any text in UITextFiled and perform a custom action - iPhone 4

I am trying to accomplish the following:
Read and Parse the text in a UITextField. Identify all the numbers in the UITextField and convert these into hyperlinks.
When these hyperlinks are clicked perform a custom action, which is to display a UIActionSheet and based on the selection assign the number (in the hyperlink) to another UITextField instance
For example if the UITextField has the text - "This is a sample test with number 123445 and more numbers 44555, 66777".
I should be able to parse the above text, detect all three numbers and add hyperlinks to them.
For the first part (parsing) I found out that there is a NSRegularExpression class that can be used to detect patterns in a text. But I could not find a way of adding hyperlinks to the matched numbers. I tried looking at Three20 documentation and could not figure out a way. Even tried the answer in this link - Just how to you use TTStyledTextLabel? but it only auto detects URLs and adds hyperlinks to them, I want to add hyperlinks to any custom text.
Can someone please help me with this. Please do not ask me to use WebView. I would really appreciate some code snippets. Thanks in advance. I am using xCode4.
If you don't need the text to be user-editable directly, you may use my OHAttributedLabel class to achieve this. (here on github)
This allows you to display any NSAttributedString and can also autodetect links, phone numbers and everything Apple's NSDataDetector class is able to detect. You can also add custom links to your label on any part of the text.
See the sample project included in my github repository for more details.
It is very customizable, both for link colors, underline style, action to perform when a link is tapped, which link types it should autodetect, and you can add any custom links and style you need on the text.

Large scrollview table with buttons

We are trying to write a training manual application for the iPhone. On the top half of the screen is a diagram of a car engine, on the bottom half is some text. At the user repeatedly hits a "next" button, we highlight different parts of the engine, and in concert we highlight different parts of the descriptive text below.
We basically want "living text" in the text half, with the illustration following along on top to where the reader is in the text. What we'd like from the text is 1. user can scroll it using their thumb so possibly a UIScrollView 2. the software can explicitly drive a scroll to any part of the text (when they hit the "next" button). 3. the words in the text are interspersed with hotlinks e.g. "this is the camshaft... this is the piston..." and the user should be able to click on any of the keywords like camshaft, piston, and have the diagram highlight that. (The problem is not highlighting the diagram, its capturing the click). The text would have 300~400 buttons/links/keywords and about 600 words of text.
Since this is fairly similar to using a web browser, we tried using Apple's version of webkit using a UIWebView and handleOpenURL to register a service back to the app itself. But Webkit for internal links a popup comes up asking permission to access that link. Every single the user wants to go to a link (in our case just an internal event that we'd intercept so that we can highlight e.g. the camshaft). Tried to intercept the event from the HTML view, but that didn't work.
It seems like the best we can do is to abandon scrolling text, and make the text part more like flash cards or a power point presentation, breaking the text into custom UIViewCells with buttons inside a UIScrollView. However, this would impose an annoying constraint on the author that they would have to write everything to fit in the UIViewCells, sort of chunky.
Any ideas would be appreciated.
This is definitely something you can use a UIWebView for. Don't use handleOpenURL, rather, set your viewController as the webview's delegate, and override -webView:shouldStartLoadWithRequest:navigationType:. When this gets called, check the request, and pull out your link data from there.
It would probably be easier to implement that completely in JavaScript in the document you load in a UIWebView. You would have to use JavaScript (i.e. [UIWebView stringbyevaluatingjavascriptfromstring:]) anyway to achieve things like scrolling to a certain position.

Laying out UIButtons - easy way?

I am making a table which has a row that looks like the "To:" line in the Apple Mail app. When you add new people to Mail from your address book, their name shows up in a rounded button.
I can create the button and use sizeToFit to make it fit snugly around the text - no problem.
However, once I do that, I can't figure out how wide the button has become. Is there an easy way to just stick a bunch of buttons in a cell and have it wrap as necessary automatically, or do I have to manually calculate the width and if it goes beyond the end of the screen, move to the next row?
Also, how do you get the width of a sizeToFit'ted button? button.frame returns null. Most perplexing.
You might want to take a look at Joe Hewitt's three20 project, a collection of custom UI elements for the iPhone that were used in the development of the Facebook app.
The two classes you would be particularly interested are TTMessageController and TTPickerTextField.
From the project site:
TTMessageController emulates the
message composer in Apple's Mail app.
You can customize it to send any kind
of message you want. Include your own
set of message fields, or use the
standard "To:" and "Subject:".
Recipient names can be autocompleted
from a data source that you provide.
TTPickerTextField is a type-ahead
UITextField. As you type it searches a
data source, and it adds bubbles into
the flow of text when you choose a
type-ahead option. I use this in
TTMessageController for selecting the
names of message recipients.