问题描述
我一直在使用第一个响应者作为代理对象,并从按钮拖动连接,以创建可用的操作(左对齐,右对齐等)。但是,默认情况下,第一个响应程序不包含粗体和斜体操作。我试图添加这些操作通过打开我的Menu.xib和拖动(字体>粗体)菜单项到第一个响应者,并将其设置为boldIt函数(自定义),但覆盖现有的操作(字体管理器:添加)。有没有办法在document.xib上有效地添加一个粗体/斜体按钮?似乎很多工作的东西这么常见。 Obj-C新手
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
Best,Zach
推荐答案
在菜单xib中,有一个对象(粗体菜单项),其标签为2,其操作连接到NSFontManager实例的-addFontTrait:方法。
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.
你只需要在文档xib中做同样的事情。添加NSFontManager对象;创建你的粗体按钮;将其标记设置为2;并将其操作连接到NSFontManager上的-addFontTrait。
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.
这篇关于基于文档的应用程序中的Bold +斜体快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!