• 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: How to draw NSString with centered alignment?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to draw NSString with centered alignment?


  • Subject: Re: How to draw NSString with centered alignment?
  • From: "I. Savant" <email@hidden>
  • Date: Tue, 23 Jan 2007 00:23:29 -0500


The -drawAtPoint:... method starts the left side of the string at the point you specify. To center it that way, you need to take half the width of the area in which you want to center the string, minus half the width of the attributed string.


... or you could just use the -drawInRect:... method and let the paragraph style "Do the Right Thing". :-)

--
I.S.


On Jan 23, 2007, at 12:02 AM, Joe Goh wrote:

Heya everyone,

I'm having trouble figuring out how to draw an NSString with centered
alignment, given an NSPoint.  My approach now is to use a paragraph
style, but that isn't working at all.

Here's what i'm trying now:
------CODE SNIPPET-------------------
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle
alloc] init] autorelease];
[paragraphStyle setAlignment:NSCenterTextAlignment];

NSDictionary *attributes = [NSDictionary
dictionaryWithObjectsAndKeys:paragraphStyle,
NSParagraphStyleAttributeName, nil];

[someString drawAtPoint:NSMakePoint(x, y) withAttributes:attributes];
------END CODE SNIPPET---------------

Thanks!
Joe Goh
FunkeeMonk Technology
http://www.funkeemonk.com/
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: How to draw NSString with centered alignment?
      • From: "Joe Goh" <email@hidden>
References: 
 >How to draw NSString with centered alignment? (From: "Joe Goh" <email@hidden>)

  • Prev by Date: How to draw NSString with centered alignment?
  • Next by Date: Re: How to draw NSString with centered alignment?
  • Previous by thread: How to draw NSString with centered alignment?
  • Next by thread: Re: How to draw NSString with centered alignment?
  • Index(es):
    • Date
    • Thread