• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iTunes header column and Rows selection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iTunes header column and Rows selection


  • Subject: Re: iTunes header column and Rows selection
  • From: Jeremy Dronfield <email@hidden>
  • Date: Wed, 18 Feb 2004 17:57:45 +0000

On 18 Feb 2004, at 4:53 pm, Roberto Sobachi wrote:
How can I do header Columns of my NSTableView as iTunes (a dark grey)?

Two cunning approaches are open to you in order to achieve this stupendous effect: 1) Read some of the documentation that came with your dev tools; or if you're too lazy to do that, 2) Copy the code below. (First you will have to create or "borrow" an image for the raised metallised look.)

This might not be the very best way to achieve the effect; my excuse is that I worked out how to do it myself.

Put this somewhere:

//get some frames to work with
NSRect superRect = [[myTable headerView] frame];
NSRect cornerRect = [[myTable cornerView] frame]; //if your table is scrollable, you'll need this

//allocate a header view to hold everything - you'll have to retain this instance, since your table won't
myHeader = [[NSTableHeaderView alloc] initWithFrame:superRect];
[myHeader setAutoresizesSubviews:YES];

// a white shadow to give your header title that "engraved" look
// you can play around with the values - these are the ones I found look best
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowOffset:NSMakeSize(1.1, -1.1)];
[shadow setShadowBlurRadius:0.2];
[shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.6]];

//create your title text
NSMutableAttributedString *headerString = [[NSMutableAttributedString alloc] initWithString:@"Title"];
NSRange range = NSMakeRange(0, [headerString length]);
[headerString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:11.0] range:range];
[headerString addAttribute:NSShadowAttributeName value:shadow range:range];
[headerString setAlignment:NSCenterTextAlignment range:range];

//set up your header view image
NSImageView *imageView = [[NSImageView alloc] initWithFrame:superRect];
[imageView setImageFrameStyle:NSImageFrameNone];
[imageView setImageAlignment:NSImageAlignCenter];
[imageView setImageScaling:NSScaleToFit];
[imageView setImage:[NSImage imageNamed:@"Groovy Metal Hump"]];
[imageView setAutoresizingMask:NSViewWidthSizable];

//set up your corner view image
NSImageView *cornerImage = [[NSImageView alloc] initWithFrame:cornerRect];
[cornerImage setImageFrameStyle:NSImageFrameNone];
[cornerImage setImageAlignment:NSImageAlignCenter];
[cornerImage setImageScaling:NSScaleToFit];
[cornerImage setImage:[NSImage imageNamed:@"Groovy Metal Hump"]];

//set up your title text in a text field and make the field transparent
NSTextField *headerText = [[NSTextField alloc] initWithFrame:superRect];
[headerText setAutoresizingMask:NSViewWidthSizable];
[headerText setDrawsBackground:NO];
[headerText setBordered:NO];
[headerText setEditable:NO];
[headerText setAttributedStringValue:headerString];

[myHeader addSubview:imageView];
[myHeader addSubview:headerText];
[myTable setHeaderView:myHeader];
[myTable setCornerView:cornerImage];

[headerText release];
[imageView release];
[cornerImage release];
[headerString release];
[shadow release];

That should do it.
-Jeremy

========================================
email@hidden

theLocustFarm.net:
- fractious fiction at http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >iTunes header column and Rows selection (From: Roberto Sobachi <email@hidden>)

  • Prev by Date: Re: iTunes header column and Rows selection
  • Next by Date: RE: Have to subclass NSToolbarItem to be able to disable it?
  • Previous by thread: Re: iTunes header column and Rows selection
  • Next by thread: Have to subclass NSToolbarItem to be able to disable it?
  • Index(es):
    • Date
    • Thread