• 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
Trouble getting a font to line up with the top of a frame
[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


  • 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


  • Prev by Date: Re: Disabling Display of JPG and PDF Files in NSTextView
  • Next by Date: Re: cancel editing text in a row
  • Previous by thread: Bug? - Binding NSComboBox Enabled
  • Next by thread: [NSApple setApplicationIconImage:]
  • Index(es):
    • Date
    • Thread