• 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: Positioning a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Positioning a string


  • Subject: Re: Positioning a string
  • From: Ricky Sharp <email@hidden>
  • Date: Mon, 30 Jan 2006 17:36:51 -0600


On Jan 30, 2006, at 4:00 PM, Julio Cesar Silva dos Santos wrote:

I am experiencing a little trouble with a string I want to draw in an NSRect and as the coordinates in Cocoa are upside-down

Actually, things are finally right-side up :)

I am totally confused. This string has a variable height but I want to put it always on the same point from the top of outerSize:

NSSize outerSize = [self bounds].size;
NSSize stringSize = [theString sizeWithAttributes:stringAttrib];
NSPoint stringPoint = NSMakePoint(fixedWidth, fixedHeight);
[theString drawAtPoint:stringPoint withAttributes:stringAttrib];

What is the calculation that I must do to get fixedHeight say, 32 pixels from top? I know, this is basic but I do not get it.

So you want 32 pixels between the top of your string and the top of the rectangle?


When you draw a string using drawAtPoint, it is positioned according to it's baseline.

The y-coodinate of the point given to drawAtPoint: should thus be:


NSRect theBounds = [self bounds];
float y = (theBounds.origin.y + outerSize.height) - 32 - theFontAscender;


where theFontAscender is the value returned from sending the ascender message to the appropriate font object.

Note that theBounds.origin.y can be removed if your bounds will always have a y-coord of 0.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
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


  • Follow-Ups:
    • Re: Positioning a string
      • From: email@hidden
References: 
 >Positioning a string (From: Julio Cesar Silva dos Santos <email@hidden>)

  • Prev by Date: Is anyone using chudStartRemotePerfMonitor on 10.4?
  • Next by Date: Re: To thread or not to thread?
  • Previous by thread: Re: Positioning a string
  • Next by thread: Re: Positioning a string
  • Index(es):
    • Date
    • Thread