• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how do I make chat bubbles using a custom cell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how do I make chat bubbles using a custom cell


  • Subject: Re: how do I make chat bubbles using a custom cell
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 15 Jul 2008 22:56:58 -0700


On 15 Jul '08, at 8:08 PM, TARUN CHAPLOT wrote:

I am very new to objective C and working on some application which needs to create Chat bubbles similar to iChat.
Can anybody help me to find some documentation or the sample code which will help me to make chat bubbles using custom cell.

A custom cell isn't a good way to go about this! If you do that, you have to do text layout inside every cell to compute its height, which is quite expensive, and has to be recalculated any time the view changes width. It also makes it impossible to select text in more than one cell.


iChat used an NSTextView subclass for the chat display, which overrode -drawViewBackgroundInRect (?) to draw the bubbles before the regular text-view code drew the text on top. To find the bounds of the bubbles it searched the backing store for text ranges marked with a custom attribute that indicated they were chat messages, then asked the layout manager for the bounding box of each glyph range. That's the gist of it; the details got very nasty, especially making it perform well as the number of messages increased.

In Leopard I believe they switched to using a WebView with a special CSS stylesheet. Safari supports some CSS 3 selectors that make this a lot easier than it's been in the past; in particular, there's a selector to specify a single background image for a block that slices the image into 9 pieces that get applied to the center, edges and corners.

It's probably pretty clear that this is not a newbie project. : ( Ironically, I did start working on the first iChat prototype the day I left the Cocoa training class, but my first implementation used an NSMatrix with a cell for each balloon, which is how I learned that this approach doesn't work very well. It's fairly simple, though. You just make an NSMatrix of NSTextFieldCells and add a row for every message. You can subclass NSTextFieldCell and override one of the drawing methods to draw the balloon background (at the time I just made an NSBezierPath and filled and outlined it with a solid color.)

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >how do I make chat bubbles using a custom cell (From: TARUN CHAPLOT <email@hidden>)

  • Prev by Date: Re: Redrawing CALayer subclass when super layer is scaled
  • Next by Date: Text selection in NSTableView
  • Previous by thread: Re: how do I make chat bubbles using a custom cell
  • Next by thread: Re: how do I make chat bubbles using a custom cell
  • Index(es):
    • Date
    • Thread