How to increase the height of NSTableHeaderView?

独自空忆成欢 提交于 2019-12-02 21:27:43

You don't need to subclass NSTableHeaderView.

I was able to change the height of the header view using the following snippet in the controller class:

-(void)awakeFromNib {
    NSRect frame = tableView.headerView.frame;
    frame.size.height = 26;
    tableView.headerView.frame = frame;
}

It should be noted that the scroll view takes care of the layout. It automatically changes the frame of the headerView as necessary, but leaves the height intact. Resizing the clip view etc as suggested in the other answer is not necessary.

Following link helped me in solving the issue.

http://lists.apple.com/archives/cocoa-dev/2003/Feb/msg00676.html

You need to set the Frame for NSClipView, NSTableHeaderView and the CornerView This is how I implemented the same in Code.

for(NSView * subview in [topScrollView subviews])
{           
   for(NSView * subSubView in [subview subviews])
   {
      if([[subSubView  className] isEqualToString:@"NSTableHeaderView"] &&  [[subview className] isEqualToString:@"NSClipView"]) 
      {
         [subSubView setFrameSize:NSMakeSize(subSubView.frame.size.width, subSubView.frame.size.height+5)];//HeaderView Frame
         [subview setFrameSize:NSMakeSize(subview.frame.size.width, subview.frame.size.height+5)];//ClipView Frame
      }

    }
    if ([[subview className] isEqualToString:@"_NSCornerView"])
    {
       [subview setFrameSize:NSMakeSize(subview.frame.size.width, subview.frame.size.height+5)]; //CornerView Frame
    }
}

You can also create a NSTableHeaderView object, initialize it with a frame(rect with height and width) and set that NSTableHeaderView object to your table view.

 NSTableHeaderView *tableHeaderView = [[NSTableHeaderView alloc] initWithFrame:NSMakeRect(0, 0, 120, 60)];
    [myTableView setHeaderView:tableHeaderView];
[tableHeaderView release];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!