RE: iPhone app with searchable text that highlights
RE: iPhone app with searchable text that highlights
- Subject: RE: iPhone app with searchable text that highlights
- From: Jonathan Schmidt <email@hidden>
- Date: Mon, 16 Aug 2010 12:58:17 -0400
- Acceptlanguage: en-US
- Thread-topic: iPhone app with searchable text that highlights
I would like to display this in a ScrollView. From what I have read so far, it seems that the following may be the best way:
1. Copy the String into an NSMutableAttributedString.
2. Add the attributes to the string.
3. Push a new view onto the stack with a ScrollView.
4. Use CoreText to draw the NSMutableAttributedString inside the ScrollView.
I think I can manage 1-3. How do I accomplish #4 when I don't know the Y value for the CGRect? Anyone have any sample code to use Core Text to draw an NSMutableAttributedString into a ScrollView?
Thanks,
Jonathan
________________________________________
From: Conrad Shultz [email@hidden]
Sent: Friday, August 13, 2010 4:43 PM
To: Jonathan Schmidt
Cc: email@hidden
Subject: Re: iPhone app with searchable text that highlights
On Aug 12, 2010, at 17:31, Jonathan Schmidt <email@hidden> wrote:
> At its most basic level, I am creating an iPhone app that displays textual information. When searching, I want the app to highlight the matching text. I'm using Core Data with SQLite. The text is stored in a string attribute right now. The strings can be up to a few kilobytes in size.
>
> I think I need to use the web view to do this? Anyone know of any sample code out there that can do this?
>
You don't say where you are planning to display the results. If you are intending to use the result in a UITableView, I think you can throw out the UIWebView approach... there seems to be an inevitable loading delay with UIWebView that becomes a major nuisance in a scrolling table. Furthermore you run into a problem returning proper values in the UITableView heightForRowAtIndexPath: delegate method - your UIWebView won't have loaded by the time the row height is requested.
If you are not displaying in a UITableView these problems are less severe to non-existent, and it becomes a simple matter of rendering out HTML with loadHTMLString: or the like.
We have an app with very similar behavior that was designed before Core Text became available. I ended up writing my own custom view code that composites text and background views, with pixel-precise positioning courtesy of the various string size methods furnished by the UIKit additions to NSString. If I had to do it over, though, I would learn to use Core Text; my current approach is rather inelegant.
If you want a quick, albeit clumsy, approach you might look at the TTStyle stuff in the three20 framework. But this is almost certainly not the best long term solution.
--
Conrad Shultz
www.synthetiqsolutions.com_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden