Trouble getting a font to line up with the top of a frame
Trouble getting a font to line up with the top of a frame
- Subject: Trouble getting a font to line up with the top of a frame
- From: Allan Dushan <email@hidden>
- Date: Wed, 14 Sep 2005 20:52:02 -0700
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:
This email sent to email@hidden