• 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
Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)
      • From: Jens Alfke <email@hidden>
    • Re: Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)
      • From: Graham Cox <email@hidden>
  • Prev by Date: NSEventTrackingRunLoopMode and mouseDown
  • Next by Date: Re: Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)
  • Previous by thread: NSEventTrackingRunLoopMode and mouseDown
  • Next by thread: Re: Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)
  • Index(es):
    • Date
    • Thread