 |
 |
Changing the Color of a Column in NSTableView
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
Still cranking and learning how to use NSTableView and related classes. I'm a little bit stuck since I'm lacking some good examples on how to do some simple things. Here are the most inmediate needs:
1. How do I change the background color of each cell in a column? You can see this in spreadsheet apps; they have the first column grayed out and use it to indicate row number. I think I have to work with NSCell but how?
2. How do I change the fonts in an individual cell.
Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
Well, here's what I got for the first item (changing the background color of cells). Too bad it doesn't work... How far am I?
Code:
NSTableColumn *firstColumn;
firstColumn = [tableView tableColumnWithIdentifier:@"0"];
NSTextFieldCell *cell;
cell = [[NSTextFieldCell alloc] init];
[cell setBackgroundColor:[NSColor lightGrayColor]];
[firstColumn setDataCell:cell];
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
Originally posted by DaGuy:
Well, here's what I got for the first item (changing the background color of cells). Too bad it doesn't work... How far am I?
Code:
NSTableColumn *firstColumn;
firstColumn = [tableView tableColumnWithIdentifier:@"0"];
NSTextFieldCell *cell;
cell = [[NSTextFieldCell alloc] init];
[cell setBackgroundColor:[NSColor lightGrayColor]];
[firstColumn setDataCell:cell];
Got it to work! I was missing the following:
Code:
[cell setDrawsBackground:YES];
Now, I need see how to workout the font deal; lets see how that goes.

|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
Done! Below is the solution. Cocoa is so freaking cool!
Code:
NSTableColumn *firstColumn;
firstColumn = [tableView tableColumnWithIdentifier:@"0"];
NSTextFieldCell *cell;
cell = [[NSTextFieldCell alloc] init];
NSFont *indexFont;
indexFont = [NSFont fontWithName:@"helvetica" size:10.0];
[cell setFont:indexFont];
[cell setDrawsBackground:YES];
[cell setBackgroundColor:[NSColor lightGrayColor]];
[cell setTextColor:[NSColor whiteColor]];
[firstColumn setDataCell:cell];

|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |