0

I've been reading into using the First Responder as a proxy object, and dragging connections from buttons in order to create usable actions (align left, right, etc). However, by default, the First Responder doesn't contain Bold and Italic actions. I tried adding these actions by opening my Menu.xib and dragging the (Font > Bold) menu item to the first responder and setting it as a boldIt function (custom) but that overwrites the existing action (Font Manager: Addtrait). Is there a way to somewhat efficiently add a bold/italic button on the document.xib? Seems like a lot of work for something so common. New to Obj-C

Best, Zach

Zakman411
  • 1,764
  • 3
  • 22
  • 45

1 Answers1

2

In the menu xib, there is an object (the Bold menu item), whose tag is 2, and whose action is connected to the -addFontTrait: method of an NSFontManager instance.

You simply need to do the same thing in document xib. Add an NSFontManager object; create your Bold button; set its tag to 2; and connect its action to -addFontTrait on the NSFontManager.

Ross Carter
  • 552
  • 4
  • 12
  • Thank you Ross - that works. Do you know how to allow the same button to turn a trait on & off? right now it only 'adds' bold, but it won't turn it off... – Zakman411 Jan 26 '11 at 02:10
  • This is covered in Apple's Font Handling guide. Note the sections Initiating Font Changes and Converting Fonts Manually. http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/FontHandling/FontHandling.html – Ross Carter Jan 26 '11 at 17:12