NSCell with divisions

杀马特。学长 韩版系。学妹 提交于 2020-03-03 12:49:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!