截断NSTextView吗? [英] Truncate NSTextView?

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

问题描述

我尝试使用defaultParagraphStyle,但似乎无法获得NSTextView(以编程方式添加)以省略号(...)截断文本.

I tried using defaultParagraphStyle, but I can't seem to get a NSTextView (programmatically added) to truncate text with an ellipsis (...).

我正在initWithFrame(150,20)期间设置框架,并且还设置了maxSize(150,20).但是,文本只会溢出.如果将高度设置为可见一半行,则可以看到文本的上半部分,但是我希望看到文本被省略号截断.

I am setting the frame during the initWithFrame (150, 20) and I also set the maxSize (150,20). However, text simply overflows. If I set the height where half a line is visible, I can see the top half of the text, however I would like to see the text truncated with ellipsis instead.

我该怎么做?

推荐答案

如果将鼠标悬停在IB中的相应控件上,则可以看到有关其触发方法的声明和简要说明(通常是getter而不是setter,但从另一个推论一个就足够容易了.因此,例如对于换行符"弹出窗口,您将看到lineBreakMode方法.然后,您可以使用自己喜欢的方法在Xcode中找到它(例如快速打开").

If you hover over the corresponding control in IB, you can see the declaration and brief documentation on the method that it triggers (usually the getter rather than the setter, but it's easy enough to infer one from the other). So for example for the "Line Breaks" popup, you'll see the lineBreakMode method. Then you can use your favorite method to find it in Xcode (e.g. "Open Quickly").

所以您想要的是:

[[someTextField cell] setLineBreakMode:NSLineBreakByTruncatingTail];

或可能:

[[someTextField cell] setLineBreakMode:NSLineBreakByCharWrapping];
[[someTextField cell] setTruncatesLastVisibleLine:YES];

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

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