0

I'm wanting to create a read only text area in my app which allows the user to click on any word and the app reads it out. I am however a little confused on which method would be the best. I see two options, use a UILabel and create some method to detect the region clicked then match it to the word in that region but it sounds hard to implement. On the other hand I could use an array of words to create a list of UIbutton's. Any advice and/or sample code to help me would be much appreciated, thanks Jason.

Note: Each view has about 30 words on it.

The solution below works well. For anyone else wanting to use this, these four lines will set your UIWebView to have a clear background and disable any scrolling or bounce.

[[myWebView.subviews objectAtIndex:0] setScrollEnabled:NO];
[[myWebView.subviews objectAtIndex:0] setBounces:NO];
[myWebView setBackgroundColor:[UIColor clearColor]];
[myWebView setOpaque:NO]; 

And some handy css to stop the open popup when a user presses and holds a link.

*{-webkit-touch-callout:none; -webkit-user-select: none;} 
dciso
  • 1,264
  • 3
  • 18
  • 31

1 Answers1

4

How big is your text area? If it's big then creating a UIButton for each work sounds like sa bit of effor to get the text to layout correctly.

I would use a UIWebView - make each word like this :

<a href="wordpress://WORD1">WORD1</a> <a href="wordpress://WORD2">WORD2</a> <a href="wordpress://WORD3">WORD3</a>

and attach your view controller as the webView's UIWebViewDelegate delegate.

Then, you can intercept presses on each word using the webView:shouldStartLoadWithRequest:navigationType: delegate method :)

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • HI dean thanks for your answer.. I am new to ios could you ellaborate your answer please.. i.e how to add text in to UI webview thanks much appreciated – vinothp Aug 12 '12 at 10:48
  • Check out the docs (http://developer.apple.com/library/ios/ipad/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html), specifically the loadHTMLString:baseURL: method -pass your HTML string as the first parameter and nil as the second. Then, if you implement the delegate methods you will be told each time someone clicks on a link. – deanWombourne Aug 12 '12 at 20:22