• 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
Re: Questiong on NSString sizeWithAttributes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Questiong on NSString sizeWithAttributes


  • Subject: Re: Questiong on NSString sizeWithAttributes
  • From: Stephane Sudre <email@hidden>
  • Date: Tue, 8 Nov 2005 18:20:05 +0100


On 8 nov. 05, at 17:54, Ed Voas wrote:

Hi,

I'm seeing something strange, and maybe I'm doing something wrong. I have two text objects I'm trying to draw and need to position them exactly. Both are being drawn in Arial Bold. One is 16pt and the other is 12.

When I ask for the 16pt height via sizeWithAttributes, I'm told it has a height of 18. Seems reasonable given the font ascent/descent. But when I ask for the 12 point type height, I get... 18. This time, it's not so cool. In theory I should be getting a height of about 13 or 14. This is causing me to position my text (in this specific case) 4 pixels off from where it should be. The font reports the line height to be 14 for the 12 point text, btw, which sounds right. Yet sizeWithAttributes reports 18.

I use the height to build my rectangle for my view. But we specify our text items via baseline. So when given a value of 20, say, I normally get the text ascent, subtract that and get the top and then add the height for the bottom (this is in top-left-speak, even in bottom left the same ideas apply). If I draw the text with a background color I get 4 pixels of color where none should (in my mind) appear.

Personally, I have given up on using sizeWithAttributes to get the height of the string.


I'm using the NSFont methods to get what I want which sometimes lead to mixing things such as:

[tFont defaultLineHeightForFont]

[tFont descender];

etc...

Somewhere on the Net, there is a nice exemple showing what these values exactly represents for a NSFont but I have lost the URL :(

_______________________________________________
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


References: 
 >Questiong on NSString sizeWithAttributes (From: Ed Voas <email@hidden>)

  • Prev by Date: Questiong on NSString sizeWithAttributes
  • Next by Date: Using NSSocketPort, NSConnection, Distributed Objects, and threads...
  • Previous by thread: Questiong on NSString sizeWithAttributes
  • Next by thread: Re: Questiong on NSString sizeWithAttributes
  • Index(es):
    • Date
    • Thread