Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)
Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)
- Subject: Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)
- From: Chunk 1978 <email@hidden>
- Date: Tue, 27 Oct 2009 07:59:41 -0400
while the following works, this seems to me like an awful lot of code i've
written just to change the font mask. any suggestions?
-=-=-=-=-
- (void)prepareAttributes
{
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowOffset:NSMakeSize(-3, -3)];
[shadow setShadowBlurRadius:5];
[shadow setShadowColor:[NSColor blackColor]];
attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:[NSFont fontWithName:@"Helvetica" size:75] forKey:
NSFontAttributeName];
[attributes setObject:[NSColor redColor] forKey:
NSForegroundColorAttributeName];
[attributes setObject:shadow forKey:NSShadowAttributeName];
[shadow release];
}
- (IBAction)fontMask:(id)sender
{
NSFontManager *fm = [NSFontManager sharedFontManager];
NSFont *currentFont = [attributes objectForKey:NSFontAttributeName];
NSObject *newFontMask;
//Bold Font Mask
if ([sender tag] == 1)
if ([sender state] == NSOnState)
newFontMask = [fm convertFont:currentFont toHaveTrait:NSBoldFontMask];
else
newFontMask = [fm convertFont:currentFont toHaveTrait:NSUnboldFontMask];
//Italic Font Mask
if ([sender tag] == 2)
if ([sender state] == NSOnState)
newFontMask = [fm convertFont:currentFont toHaveTrait:NSItalicFontMask];
else
newFontMask = [fm convertFont:currentFont toHaveTrait:NSUnitalicFontMask];
[attributes setObject:newFontMask forKey:NSFontAttributeName];
[self setNeedsDisplay:YES];
}
-=-=-=-=-
_______________________________________________
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