Re: How to make letters appear in italics?
Re: How to make letters appear in italics?
- Subject: Re: How to make letters appear in italics?
- From: Jim Correia <email@hidden>
- Date: Tue, 17 Mar 2009 17:16:08 -0400
On Mar 17, 2009, at 10:14 AM, Li Fumin wrote:
Hi,all.I am new to cocoa. I am reading Aaron Hillegass's Book "Cocoa
Programming for Mac OS X".
I have got some problems with challenge 2 of Chapter 20.I have a
custom NSView called BigLetterView, and then it show the input
letter on the view.Now I want to make the letter which I just
inputted appears in italics. So, I define this method:
- (IBAction) isItalic: (id) sender
{
if ([italicBox state])
{
NSFontManager *fontManager = [NSFontManager sharedFontManager];
[fontManager convertFont: [NSFont fontWithName: @"Helvetica" size:
75]
toHaveTrait:
NSItalicFontMask];
}else {
NSFontManager *fontManager = [NSFontManager sharedFontManager];
[fontManager convertFont: [NSFont fontWithName: @"Helvetica" size:
75]
toHaveTrait:
NSUnitalicFontMask];
}
[self setNeedsDisplay: YES];
}
When I click the italics check button. Nothing happens. How do I
suppose to make this wok?
How can I get the font the letter is using?
Look at the API doc and method prototype for -convertFont:toHaveTrait:.
It returns a new font. You discard the return value, and don't update
any of your own state, so I'm not sure how you envisioned this to work.
In the case where you want to remove the italic attribute, you should
be using -convertFont:toNotHaveTrait:.
- Jim
_______________________________________________
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