问题
I want to know if there is a way of drawing an NSCell like the following sample. The idea is to fit in the same column, 3 rows, the first one with enough space for a Title, and the rest with 2 columns.
TITLE______________________________________________________
DATA_TITLE_1: DATA_VALUE_1 _ _ _ DATA_TITLE_2: DATA_VALUE_2
DATA_TITLE_3: DATA_VALUE_1 _ _ _ DATA_TITLE_4: DATA_VALUE_2
Notes:
- The "_ _ _" were suposed to be three spaces (I don't know how to represent them).
- Bare in mind that the column titles and values length will vary.
Thanks in advance.
回答1:
There's no standard NSCell that can do this, but you can write your own subclass of one of the NSCell classes and make it do this. See the Control and Cell Programming Topics.
回答2:
As it turns out, when subclassing NSCell you may add as many cells within the frame as you want. You've just have to override the drawInteriorWithFrame method alloc an NSCell and then draw it anywhere within the frame of the cell.
Here it's a simple example:
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSRect modifiedFrame = NSMakeRect(cellFrame.origin.x +10, cellFrame.origin.y +10, cellFrame.size.width -10, cellFrame.size.height -10);
NSTextFieldCell *modifiedCell = [[NSTextFieldCell alloc] initTextCell:@"TEST"];
[modifiedCell drawWithFrame:modifiedFrame inView:controlView];
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
来源:https://stackoverflow.com/questions/6576180/nscell-with-divisions