【问题标题】:AutoScroll down in a NSTextField in Swift在 Swift 中的 NSTextField 中自动向下滚动
【发布时间】:2014-08-15 22:20:50
【问题描述】:

我正在尝试找到一种在 NSTextField 末尾自动向下滚动的方法。 textField 循环更新,所以我想知道如何通过向下滚动显示每次输入的最后一个文本。

这是我的代码:

var tmp = consoleView.stringValue.utf16Count
if tmp >= 25000
{
    consoleView.stringValue = "";
}
consoleView.stringValue = //[..longStringHere..]
consoleView.//SCROLLDOWN

我在objective-c中看到了一些答案,但我从来没有在其中做过任何程序,所以我不太了解它......

谢谢

【问题讨论】:

    标签: swift nstextfield autoscroll


    【解决方案1】:

    对于滚动,我认为您宁愿需要NSTextView

    textView.scrollRangeToVisible(
          NSRange(location: countElements(textView.string!), length: 0))
    

    【讨论】:

    • 我试图用 NSTextView 来做,但我无法再编辑文本(没有找到 .stringValue 或 .text...)
    • NSTextViewNSText 的子类。您可以通过其属性string 检索没有属性的文本,如上所示。
    猜你喜欢
    • 2021-12-16
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多