0

我有一个 NSTextView 来显示长行的数字数据,由制表符分隔。我无法阻止固定长度后的换行符。作为测试。我使用字符串:显示一长行纯 textA 工作正常:TextB 在 9 个块后换行: 我的代码:(downloadDataFeld 是 NSTextView)
在此处输入图像描述
在此处输入图像描述

let textA = "asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh  asdfgh    \n"
let textB = "asdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \tasdfgh  \n"

let paragraphStyle = NSMutableParagraphStyle()
let tabInterval:CGFloat = 20.0
let tabs:NSMutableArray = NSMutableArray.init()

for cnt in 0..<24 
{    // Add 24 tab stops, at desired intervals...
   paragraphStyle.tabStops.append(NSTextTab(textAlignment: .left, location: (CGFloat(cnt) * tabInterval), options: [:]))
}

let attrtext = NSMutableAttributedString(string: textB)
let textRange = NSMakeRange(0, textB.characters.count)
attrtext.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: textRange)
// load the text
downloadDataFeld.textStorage?.append(attrtext)

TextView 设置是:(
我必须在代码中明确设置 documentView 的 with 才能获得没有标签的工作结果)

downloadDataFeld.delegate = self
  downloadDataFeld.enclosingScrollView?.documentView?.frame.size.width = 2000 // muss
  downloadDataFeld.enclosingScrollView?.hasHorizontalScroller = true
  downloadDataFeld.enclosingScrollView?.hasVerticalScroller = true
  downloadDataFeld.enclosingScrollView?.autohidesScrollers = false

我找不到任何东西来设置换行符。我错过了什么?

4

0 回答 0