Optimized Method for Ellipses in NSTableView?
Optimized Method for Ellipses in NSTableView?
- Subject: Optimized Method for Ellipses in NSTableView?
- From: Buzz Andersen <email@hidden>
- Date: Fri, 09 Aug 2002 15:32:13 -0600
All,
I am trying to make my NSTableView emulate the iTunes table view's behavior
in terms of putting ellipses at the end strings that are too long to fit
within the current column width. Here is my crack at it, which works fairly
well (it is called by my data source's "objectValueForTableColumn" method
before it actually returns the current string). I was wondering, however,
if someone might be able to point me toward a simpler or more optimized way
of doing it? It does get called for *every* cell, *every* time a user
resizes a column or re-sorts, so I want to make sure there isn't a better
way to do it!
- (NSString *) stringWithEllipses: (NSString *) theString forCell: (NSCell
*) theCell withColumnWidth: (long) columnWidth {
NSDictionary *attributes = [NSDictionary dictionaryWithObject: [theCell
font] forKey: @"NSFontAttributeName"];
NSAttributedString *attString = [[NSAttributedString alloc]
initWithString: theString attributes: attributes];
NSSize stringSize = [attString size];
[attString release];
if (stringSize.width > columnWidth) {
// RETURN STRING WITH ELLIPSES
}
else {
return theString;
}
}
Thanks in advance for your help!
--
Buzz Andersen
email: email@hidden
web:
http://www.scifihifi.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.