Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble getting a font to line up with the top of a frame



I am having trouble getting a font to line up with the top of a frame.

What I am trying to do is use an NSTextField with an attributed string. I am attempting to set up the attributed string so that it will draw the font so that the top of the font starts at the top of the frame with a line spacing of 1.0.

Here is what I am doing. For some fonts it appears to work okay, and for other fonts it is clipping the top of the font.

// Create the paragraph style...
paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setLineBreakMode:NSLineBreakByCharWrapping];
[paragraphStyle setAlignment:inAlignment];
[paragraphStyle setLineSpacing:1.0];
[paragraphStyle setParagraphSpacingBefore:1.0];
[paragraphStyle setMaximumLineHeight:f[theFont ascender]]; // This works for some fonts and other fonts it clips the top...


// Set the attributes for the string...
theRange.location = 0;
theRange.length = [muteAttrString length];
[muteaAttrString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:theRange];
[muteAttrString addAttribute:NSFontAttributeName value:theFont range:theRange];
[muteAttrString addAttribute:NSForegroundColorAttributeName value:theColor range:theRange];


// Set the attributed string in the text field...
[theTextField setAttributedStringValue:muteAttrString];

What's the trick to always getting a font to draw at the top of the frame?

Allan



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.