简体   繁体   English

NSTextView 文本对齐

[英]NSTextView Text Alignment

well, I was searching for the code to make the "Left/Center/Right" Alignment for the NSTextView.好吧,我正在寻找使 NSTextView 的“左/中/右”对齐的代码。 I observe that in Text Menu, this functionality exists, and it is linked to the first responder calling the "alignCenter" selector.我观察到在文本菜单中,此功能存在,并且它链接到调用“alignCenter”选择器的第一响应者。 However I could not make it to work.但是我无法让它工作。

So I start to read the source code of TextEdit.于是我开始阅读TextEdit的源代码。 It seems that Apple implement it and shows in the toolbar.似乎Apple实现了它并显示在工具栏中。 However I was not able to find where it is.但是,我无法找到它的位置。 (It's not in any .nib file, and there's no selector related to align or centre or left, etc..) (它不在任何 .nib 文件中,并且没有与对齐或居中或左等相关的选择器。)

So can anyone tell me: how to implement the function exactly like that in the Text Menu.谁能告诉我:如何实现与文本菜单中完全相同的功能。

OR或者

Where the heck did Apple put the source code of aligning the text in their TextEdit program? Apple 到底把对齐文本的源代码放在哪里了?

NSTextView继承自NSText ,它实现了alignCenter:alignLeft:等操作。

You can use use the alignment property on NSTextView and set the alignment you want (.justified, .center, .left, .natural, etc)您可以使用 NSTextView 上的对齐属性并设置所需的对齐方式(.justified、.center、.left、.natural 等)

let textView = NSTextView()
textView.alignment = .justified

or或者

textView.alignment = .center

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM