• 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
Basic NSFont and string drawing question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Basic NSFont and string drawing question


  • Subject: Basic NSFont and string drawing question
  • From: "Christian Moen" <email@hidden>
  • Date: Thu, 28 Dec 2006 08:40:41 +0900

cocoa-dev,

I have a basic question on drawing strings in a view using a custom
font.  The following code doesn't draw the string using the specified
font:

 NSFont *font = [NSFont fontWithName:@"Helvetica" size:40.0];
 NSString *hello = @"Hello custom view";
 [font set];
 [hello drawAtPoint:NSMakePoint(300.0, 300.0) withAttributes:nil];

I was expecting that [font set] assigns the font in my view's graphics
context so subsequent drawing operations would use the font, but that
doesn't seem to be the case.  In order to draw the string using the
specified font, I'm setting the attributes explicitly:

   NSDictionary *attr = [NSDictionary dictionaryWithObject:font

forKey:NSFontAttributeName];
   [hello drawAtPoint:NSMakePoint(300.0, 300.0) withAttributes:attr];

Why doesn't the first piece of code work?  What is the effect of [font
set]?  Which drawing text drawing operations use the font set by [font
set]?

Many thanks,


Christian _______________________________________________

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: Basic NSFont and string drawing question
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: changing cell controls in an NSOutlineView
  • Next by Date: Re: Completely remove a window (from NSApp)?
  • Previous by thread: Re: changing cell controls in an NSOutlineView
  • Next by thread: Re: Basic NSFont and string drawing question
  • Index(es):
    • Date
    • Thread