在Mac上修改表标题

时间:2011-01-20 22:15:34

标签: objective-c cocoa macos interface-builder

我已经能够找到使用UITableView在iOS上修改表头的教程 - 但是还没有能够找到mac开发的任何信息。有谁知道修改表格外观的任何好资源/步骤?

扎克

2 个答案:

答案 0 :(得分:40)

要更改表头的显示方式,您需要子类化NSTableHeaderCell,在其中一个绘图方法中执行自己的自定义绘图,然后用子类的实例替换每列的标题单元格。

您可能还发现需要子类化NSTableHeaderView来绘制任何没有标题单元格可见的空间,并替换表格视图的cornerView

这应该让你开始:

for (NSTableColumn *column in [tableView tableColumns]) {
   [column setHeaderCell:
      [[[MyHeaderCell alloc]
                      initTextCell:[[column headerCell] stringValue]]
                      autorelease]];
}

这是NSTableHeaderCell的子类的起点:

@interface MyHeaderCell : NSTableHeaderCell
{
}
- (void)drawWithFrame:(CGRect)cellFrame
          highlighted:(BOOL)isHighlighted
               inView:(NSView *)view;
@end

@implementation MyHeaderCell

- (void)drawWithFrame:(CGRect)cellFrame
          highlighted:(BOOL)isHighlighted
               inView:(NSView *)view
{
   CGRect fillRect, borderRect;
   CGRectDivide(cellFrame, &borderRect, &fillRect, 1.0, CGRectMaxYEdge);

   NSGradient *gradient = [[NSGradient alloc]
      initWithStartingColor:[NSColor whiteColor]
                endingColor:[NSColor colorWithDeviceWhite:0.9 alpha:1.0]];
   [gradient drawInRect:fillRect angle:90.0];
   [gradient release];

   if (isHighlighted) {
      [[NSColor colorWithDeviceWhite:0.0 alpha:0.1] set];
      NSRectFillUsingOperation(fillRect, NSCompositeSourceOver);
   }

   [[NSColor colorWithDeviceWhite:0.8 alpha:1.0] set];
   NSRectFill(borderRect);

   [self drawInteriorWithFrame:CGRectInset(fillRect, 0.0, 1.0) inView:view];
}

- (void)drawWithFrame:(CGRect)cellFrame inView:(NSView *)view
{
   [self drawWithFrame:cellFrame highlighted:NO inView:view];
}

- (void)highlight:(BOOL)isHighlighted
        withFrame:(NSRect)cellFrame
           inView:(NSView *)view
{
   [self drawWithFrame:cellFrame highlighted:isHighlighted inView:view];
}

@end

答案 1 :(得分:0)

更改tableView中列标题的代码:

$response = $this->call('POST', 'users/?token=' . $this->token, $user, [], [], [], ['Content-Type' => 'application/x-www-form-urlencoded']);