Re: Implementing a Find menu item like Safari?
Re: Implementing a Find menu item like Safari?
- Subject: Re: Implementing a Find menu item like Safari?
- From: Jerry Krinock <email@hidden>
- Date: Thu, 27 Jan 2011 21:42:56 -0800
On 2011 Jan 27, at 19:43, Ben Golding wrote:
> Safari has a really nice "Find" bar that scrolls down from the title pane of the window. I'd like to do something like that in an application that I'm developing but I can't find out whether that's generally available and how to use it.
Well, it would be nice if someone from Apple would would chime in and say, "Glad you asked! Here's the code we wrote to do that trick." But this doesn't happen very often ;)
Assuming that's not going to happen, to add that "Find bar" you would reduce the height of the lower view using -[NSView setFrame], then slip in your "Find bar" by sending -[NSView addSubview:] to the superview (probably but not necessarily the window's -contentView), with the subview being your Find Bar View which is standing alone in some nib. To remove it, -removeFromSuperviewWithoutNeedingDisplay. 1-8 hours of work depending on your experience. Also, I think that these things can be animated with some modest additional effort.
> Further, I'd like to be able to highlight the found text in a yellow box like Safari does but again, I can't seem to find how to do that either.
In this particular case, since that's a WebView, they're likely modifying the WebView's HTML source. Assuming you're not working with a WebView, you can draw anything by overriding -drawRect:. You'll have to get into the text layout classes if you need to find the coordinates of the target word. You'll likely find that making this look pretty is a bigger challenge than your Find bar.
_______________________________________________
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