将普通字体更改为粗体字体
我如何将普通字体更改为粗体字体,应选择文本并通过单击按钮(粗体)按钮说出。所选文本应变为粗体。
How can i change a normal font to bold font, Here the text should be selected and say by clicking the button(Bold) button. the selected text should become bold.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否查看过主菜单中的“格式”菜单?有一种叫“大胆”。您应该查看与该菜单项挂钩的方法。这可能是“第一响应者”的一部分的某种方法。如果是这样,请将您的按钮连接到“第一响应者”,然后为该按钮选择该方法。
Did you look at the "Format" menu in your main menu? There's one called "Bold". You should look at the method that is hooked to that menu item. It's probably some method that's part of "First Responder". If so then hook your button up to "First Responder" and then select that method for the button.
Cocoa 文本系统已经提供了大量用于修改属性字符串和文本的子系统。在开始构建自己的系统之前,您可能应该考虑使用 NSTextView。
但是:您可能想查看
NSAttributedString
API。你应该会发现它很有启发。The Cocoa text system already provides a wide array of subsystems for modifying attributed strings and text. You should probably look into using NSTextView before you go rolling your own systems.
However: You might want to look into the
NSAttributedString
API. You should find it enlightening.粗体菜单挂钩到字体管理器而不是第一响应者。只需创建一个按钮并将标签设置为 2,然后将按钮挂接到字体管理器并选择 addFontTrait: 操作。
bold menu hook to font manager not to first responder. just create a button and set the tag as 2, then hook the button to font manager and select addFontTrait: action.