• 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
NSTextField and Formatters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextField and Formatters


  • Subject: NSTextField and Formatters
  • From: Timothy Ritchey <email@hidden>
  • Date: Tue, 5 Nov 2002 18:19:15 -0500

I have made a custom fraction formatter that takes either a float
value, or a string like # #/# and returns an attributed string using a
fractional display. Anyway, my attributed string looks good, but is
shifted down in the Text Field. I am not sure if this a problem with my
attributed string being too tall, or what. Here is the code that
creates the fractional part of the string (note: this includes an
attempt at setting the para style min/max height--it didn't make any
difference): You can see what this looks like at:
http://homepage.mac.com/tritchey/ with the file low.tiff. Any
suggestions would be appreciated.

// need to compute the right size for the fractional
// part based on the current font size
NSFont *font = [md objectForKey:NSFontAttributeName];
float size = [font pointSize];
[md setObject:[[NSFontManager sharedFontManager]
convertFont:font toSize:size*0.60]
forKey:NSFontAttributeName];
NSMutableParagraphStyle *mps = [[NSMutableParagraphStyle alloc]
init];
[mps setParagraphStyle:[md
objectForKey:NSParagraphStyleAttributeName]];
[mps setMaximumLineHeight:size];
[mps setMinimumLineHeight:size];
[mps setAlignment:NSLeftTextAlignment];
[md setObject:mps forKey:NSParagraphStyleAttributeName];

// put in numerator
[md setObject:[NSNumber numberWithInt:(size*.40)]
forKey:NSBaselineOffsetAttributeName];
append = [[NSAttributedString alloc] initWithString:
[NSString stringWithFormat:@"%d", [fn numerator]]
attributes:md];
[string appendAttributedString:append];
[append release];

// put in slash
[md setObject:[NSNumber numberWithFloat:(size*.20)]
forKey:NSBaselineOffsetAttributeName];
append = [[NSAttributedString alloc] initWithString:
[NSString stringWithString:@"/"] attributes:md];
[string appendAttributedString:append];
[append release];

// put in denominator
[md setObject:[NSNumber numberWithFloat:0.0]
forKey:NSBaselineOffsetAttributeName];
append = [[NSAttributedString alloc] initWithString:
[NSString stringWithFormat:@"%d", [fn denominator]]
attributes:md];
[string appendAttributedString:append];
[append release];

[mps release];
_______________________________________________
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.

  • Prev by Date: Re: Good ol' modal dialogs
  • Next by Date: Re: Good ol' modal dialogs
  • Previous by thread: Re: Cocoa equivalent to Javadoc?
  • Next by thread: Re: NSTextField and Formatters
  • Index(es):
    • Date
    • Thread