Re: drawing a simple string with NSFont
Re: drawing a simple string with NSFont
- Subject: Re: drawing a simple string with NSFont
- From: Scott F Bayes <email@hidden>
- Date: Tue, 7 Aug 2007 19:34:46 +0900
Hi Fritz,
Thank you! That is exactly the page I was looking for, but couldn't
find in the Apple docs.
Your example is much appreciated, too. Very similar to what I had in
mind.
Best Regards
Scottb
On Aug 7, 2007, at 19:05 , Felix Franz wrote:
Hi Scott,
I never used [myFont set] for myself, but using an attribute
dictionary is
not difficult. The keys are the same as for Attributed strings:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
AttributedStrings/Articles/standardAttributes.html#//apple_ref/doc/
uid/TP40004903>
To draw a String in red color using myFont you can construct the
dictionary
like:
NSDictionary* attributes =
[NSDictionary dictionaryWithObjectsAndKeys:myFont,
NSFontAttributeName, [NSColor redColor],
NSForegroundColorAttributeName, nil];
and then use the drawInRect:withAttributes: method:
[@"Hola" drawInRect: rect withAttributes: attributes];
(Typed in Mail, watch out for typos ...)
Cheers,
felix
On Aug 7, 2007, at 11:29 AM, Scott F Bayes wrote:
I'm trying to draw an NSString on a NSView while in its drawRect,
using
- (void)drawInRect:(NSRect)aRect withAttributes:(NSDictionary *)
attribute
from the AppKit NSString additions. I can draw the string where I
want to without problem, but I want to select a font and a font
size. "Simple Text Drawing" in the Drawing Guide says:
"For an NSString object, you can apply basic attributes (such as
font, color, and style settings) to the entire string during
drawing." Perfect!
It sounds like setting font&size can be accomplished either with
the NSDictionary *withAttributes for drawInRect above, or by
[myFont set] while in drawRect.
I find I can create what appears to be a valid NSFont, no problem.
But [myFont set] in drawRect doesn't appear to do anything, and I
don't know how to construct the NSDictionary mentioned above,
assuming it's what I need; I can't figure out what key to use.
Documentation has led me through enough twists and turns that I'm
now thoroughly confused.
Any advice or a short example would be appreciated.
Scott B
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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