Re: Setting the size of NSTableView columns
Re: Setting the size of NSTableView columns
- Subject: Re: Setting the size of NSTableView columns
- From: Eric Gorr <email@hidden>
- Date: Wed, 12 Dec 2007 21:13:34 -0500
On Dec 10, 2007, at 10:43 PM, Eric Gorr wrote:
I know what text will be appearing in the cells of my table and I am
building the table dynamically in my code.
What I would like to be able to do is explicitly set the width of my
columns to be only as wide as they need to be.
I believe I can determine the width of the text using the
sizeWithAttributes message, but I am not certain what the attributes
should be. Is it possible to determine the attributes which will be
used for table cells containing text?
Is there some other way to do what I want?
With some more research a solution I found is to do the following:
NSTextFieldCell *fieldCell = [tableColumn dataCell];
NSSize stringSize;
NSSize cellSpacing;
NSString *textString = @"00";
NSFont *cellFont = [fieldCell font];
NSDictionary *cellAttributes = [NSDictionary
dictionaryWithObject:cellFont
forKey:NSFontAttributeName];
stringSize = [textString sizeWithAttributes:cellAttributes];
cellSpacing = [cardTable intercellSpacing];
[tableColumn setWidth:ceil(stringSize.width) + ( cellSpacing.width *
2 )];
Is there any reason why this doesn't work?
I noticed that before I obtain the intercell spacing, the columns
weren't wide enough. As near as I can tell, this is the way to
determine how much space surrounds the content of a cell.
_______________________________________________
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