Basic NSFont and string drawing question
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