开发者

NSCell with divisions

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 e开发者_StackOverflow中文版nough 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.


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.


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];    
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜