PDA

View Full Version : Coding Help




sethi.hitesh
Mar 23, 2006, 02:16 AM
Hi All,

I am very new to Apple, and presently i am trying to make a screen (somehting like a contact list screen of iChat)

The problem that i am facing is that i am not able to attach a thumbnail picture of the person along with his name.

Can anybody help me as to what shall i do to have a contact list with images and name side by side.

I shall be very greatful if the replies are also CC'ed to my e mail address sethi.hitesh@gmail.com

Regds,
Hitesh



Soulstorm
Mar 23, 2006, 02:21 AM
I haven't been invlolved with iChat.. but I think you are in the wrong forum section here...

caveman_uk
Mar 23, 2006, 03:03 AM
By 'screen' do you actually mean window?

I'm sorry but it sounds that any answer I give will be really over your head at the moment. But here goes. In Cocoa you need to add the NSImage of the thumbnail as an attachment to an NSAttributedString. In other languages you'd do it differently - you don't say what language you're using.

sethi.hitesh
Mar 23, 2006, 03:22 AM
Hi Caveman,

Thanks for the reply, I am using Objective C to design the GUI .

Since i am new to programming so not clear with it, Is it possible for you to send me small demo along with the code or any kind of help.

I shall really appreciate the same.

Regds,
Hitesh

caveman_uk
Mar 23, 2006, 03:42 AM
From http://www.borkware.com/quickies/one?topic=NSString



Putting an image into an attributed string
You'll need to use a text attachment.

- (NSAttributedString *) prettyName
{
NSTextAttachment *attachment;
attachment = [[[NSTextAttachment alloc] init] autorelease];
NSCell *cell = [attachment attachmentCell];

NSImage *icon = [self icon]; // or wherever you are getting your image
[cell setImage: icon];

NSString *name = [self name];
NSAttributedString *attrname;
attrname = [[NSAttributedString alloc] initWithString: name];

NSMutableAttributedString *prettyName;
prettyName = (id)[NSMutableAttributedString attributedStringWithAttachment:
attachment]; // cast to quiet compiler warning
[prettyName appendAttributedString: attrname];

[attrname release];

return (prettyName);

} // prettyName

This puts the image at the front of the string. To put the image in the middle of the string, you'll need to create an attributedstring with attachment, and then append that to your final attributed string.


You would probably need to modify this but a buddy list is basically an NSTableView with the objectFor... datasource method returning the required attributed string. There's loads of stuff you can do with custom cells in TableViews but it's rather complicated and requires custom drawing code.