NSTextField或NSTextView? [英] NSTextField or NSTextView?

查看:114
本文介绍了NSTextField或NSTextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释一下NSTextField和NSTextView之间的主要区别是什么?我知道NSTextView具有更多功能,通常用于较长的文本,NSTextField通常用于单行纯文本字段,但是如果我理解正确,NSTextField也可以用于属性字符串和多行...

Could someone explain to me what are the main differences between NSTextField and NSTextView? I know that NSTextView has more features and is usually used for longer texts, and NSTextField is usually used for one-line plain text fields, but if I understand correctly, NSTextField can be also used with attributed strings and with multiple lines...

我特别需要的是一个控件,它将在时间轴视图内显示消息的文本,例如在Tweetie或任何其他类似软件中.我唯一的要求是:

What I need specifically is a control that would display the text of messages inside a timeline view like in Tweetie or any other similar software. The only requirements I have are:

  • 它应该在大约1-4行中显示文本
  • 它应该能够在文本中显示链接(据我了解,这在两个控件中都应该很简单-
  • it should display text in about 1-4 lines
  • it should be able to show links in the text (as I understand, this should be simple in both controls - http://developer.apple.com/mac/library/qa/qa2006/qa1487.html)
  • it should let the user select and copy the text
  • it should NOT let the user scroll the text, edit the text, or show the context menu that usually appears in editable text fields, it shouldn't even show a text cursor in this field

有这样的要求,对我来说使用NSTextField或NSTextView更好吗? NSTextField够好吗,还是NSTextView有NSTextField做不到的重要事情?

With such requirements, is it better for me to use a NSTextField or NSTextView? Is NSTextField good enough, or does NSTextView has something important that NSTextField doesn't?

推荐答案

有人可以向我解释一下NSTextField和NSTextView之间的主要区别是什么?我知道NSTextView具有更多功能,通常用于较长的文本,NSTextField通常用于单行纯文本字段,但是如果我理解正确,NSTextField也可以用于属性字符串和多行...

Could someone explain to me what are the main differences between NSTextField and NSTextView? I know that NSTextView has more features and is usually used for longer texts, and NSTextField is usually used for one-line plain text fields, but if I understand correctly, NSTextField can be also used with attributed strings and with multiple lines...

从技术上讲是正确的,但通常将文本字段用于纯文本且通常仅一行的值. (处理多行,因为文本字段可以接受它们.如果没有其他原因,请以对文本处理有意义的方式剥离换行符.)

Technically true, but you normally use text fields for values that are plain text and usually only one line. (Handle multiple lines, as a text field can accept them. If nothing else, strip the line breaks in a way that makes sense for what you're doing with the text.)

  • 它应该在大约1-4行中显示文本
  • it should display text in about 1-4 lines

NSTextView.

NSTextView.

  • it should be able to show links in the text (as I understand, this should be simple in both controls - http://developer.apple.com/mac/library/qa/qa2006/qa1487.html)

NSTextView.在NSTextField中支持链接很棘手.

NSTextView. Supporting links in an NSTextField is tricky.

  • 它应该让用户选择并复制文本
  • it should let the user select and copy the text

任何一个都可以做到这一点.

Either will work for this.

  • 它不应让用户滚动文本,
  • it should NOT let the user scroll the text,

没有NSScrollView的NSTextField或NSTextView.您可以通过从库"中拖动文本视图,然后从布局"菜单中选择未嵌入的对象"来在IB中完成后者.

NSTextField or NSTextView without NSScrollView. You can do the latter in IB by dragging a text view from the Library and then choosing "Unembed Objects" from the Layout menu.

编辑文本,

edit the text,

任何一个都可以做到这一点.

Either will work for this.

或显示通常显示在可编辑文本字段中的上下文菜单,

or show the context menu that usually appears in editable text fields,

是的,应该.您应该始终提供菜单项,例如复制"和只读服务.任一个控件都应该为您执行此操作;不要打这个.

Yes, it should. You should always offer menu items like "Copy" and read-only services. Either control should do this for you; don't fight this.

它甚至不应该在此字段中显示文本光标

it shouldn't even show a text cursor in this field

任何一个都可以做到这一点.

Either will work for this.

如果您启用了选择功能(通常应该这样做),则当用户单击该字段时,它们将显示一个光标.这是一项功能,因为它指示选择锚点用于Shift-⌘-箭头选择.

If you leave selection enabled (which you generally should), they'll show a cursor if the user clicks in the field. This is a feature, as it indicates where the selection anchor is for shift-⌘-arrow selection.

有这样的要求,对我来说使用NSTextField或NSTextView更好吗?

With such requirements, is it better for me to use a NSTextField or NSTextView?

我会使用NSTextView.

I would use NSTextView.

这篇关于NSTextField或NSTextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆