• 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
NSAttributedString in NSTextFieldCell (NSTableView)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSAttributedString in NSTextFieldCell (NSTableView)


  • Subject: NSAttributedString in NSTextFieldCell (NSTableView)
  • From: Andrew Cooper <email@hidden>
  • Date: Sat, 24 Jun 2006 03:08:27 -0500

I'm having trouble adjusting the baseline offset of a string in an NSTextFieldCell. I'm designing a UI to be driven with a touchscreen so I need something bigger than normal and so I'm wanting the font and cells in my table to be larger than usual. Because of the larger cell height and wanting to keep white space around the text i've sized the cell larger than the text and it is vertically aligned to the top edge. I'd like to center this and I am having trouble doing so.

I've found that this has been discussed before on this list, but the suggested solution of using NSAttributedStrings with the NSBaselineOffsetAttributeName attribute set to a negative value does not work for me. I can set just about any other parameter font, color, underline, strikethrough, obliqueness, etc and they all work, but anything involving the baseline like NSBaselineOffsetAttributeName or NSSuperscriptAttributeName seems to do nothing at all.

I am using a custom formatter connected to the NSTextFieldCell prototype of my table's column, shown below.
The results of this are shown in http://hkcreations.org/ attributedStringResult.png
I've made the cells very tall to illustrate that the baseline is not being affected.
I've read that I can also subclass the cell to implement my own centering, but i'd like to use this solution if possible because it's much cleaner.


Thanks to anyone who has suggestions for me.

Andrew Cooper


@implementation AMCenterFormatter - (id) init { self = [super init]; if (self != nil) { NSNumber *blOffset = [NSNumber numberWithFloat:-15.0]; NSFont *font = [NSFont systemFontOfSize:20]; attributes = [[NSDictionary alloc] initWithObjectsAndKeys: font,NSFontAttributeName, blOffset,NSBaselineOffsetAttributeName, nil]; } return self; }

- (NSAttributedString *)attributedStringForObjectValue:(id)anObject
withDefaultAttributes:(NSDictionary *)attr
{
NSString *str = [self stringForObjectValue:anObject];
return [[[NSAttributedString alloc] initWithString:str attributes:attributes] autorelease];
}


- (BOOL)getObjectValue:(id *)anObject
						 forString:(NSString *)string
			errorDescription:(NSString **)error
{
	if (anObject)
		*anObject = [[string copy] autorelease];
	return YES;
}

- (NSString *)stringForObjectValue:(id)anObject
{
	return [anObject description];
}
@end

_______________________________________________
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


  • Prev by Date: Re: Help with NSArrayController, NSTableView and NSOpenPanel
  • Next by Date: File's Owner in IB
  • Previous by thread: Re: How to Implement Film Rolls Functionality Like iPhoto
  • Next by thread: File's Owner in IB
  • Index(es):
    • Date
    • Thread