• 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: Vertically centre text in Table Views
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vertically centre text in Table Views


  • Subject: Re: Vertically centre text in Table Views
  • From: Stéphane Sudre <email@hidden>
  • Date: Sat, 24 Sep 2005 08:06:53 +0200


On samedi, septembre 24, 2005, at 02:18 AM, Jerry Krinock wrote:

on 05/09/23 16:54, Mike Abdullah at email@hidden wrote:

OK, this is driving me nuts.  How on Earth do you vertically centre
text in a table view?  I've searched through the archives and found a
few people who have asked, but there seems to be no decent answer!
Please, surely someone knows?

A better question would be: Has anyone ever figured this out on their own,
without help from cocoadev?


The answer is that you must insert a subclassed NSTableColumn into your
table, and within it over-ride -dataCellForRow: and return your own NSCell
with all the fancy stuff you want. Search these list archives at
cocoabuilder.com for: subclass NSTableColumn, etc.

Uh?!!!!! Who would want to subclass NSTableColumn just to use a custom cell?


1. subclass NSTextFieldCell

2. override drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;

3. compute the appropriate new cellFrame to have the text vertically centered (tip: you can use NSFont defaultLineHeight or other methods)

4. Call back the super method with the new cellFrame

- (void) drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
// My Nice computing modifying cellFrame


	// ...

	[super drawInteriorWithFrame:cellFrame inView:controlView];
}

5. Use the usual solution to replace the column dataCell:

NSTableColumn * tableColumn = nil;
MyNSTextFieldCell * theCell = nil;

tableColumn = [IBtableView_ tableColumnWithIdentifier: @"myColumn"];
theCell = [[MyNSTextFieldCell alloc] initTextCell:@""];

[tableColumn setDataCell: theCell];

[theCell release];


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: Vertically centre text in Table Views (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Indexing extensions/files
  • Next by Date: Modal session when opening a sheet
  • Previous by thread: Re: Vertically centre text in Table Views
  • Next by thread: How do I convert unix time to a date?
  • Index(es):
    • Date
    • Thread