开发者

iOS Clickable Words (UILabel or UIbutton's)

I'm wanting to create a read only text area in my app which allows the user to cl开发者_如何学Cick 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;} 


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜