包含选项卡时,Swift 3 NSTextView包含长换行符

时间:2017-07-25 09:20:10

标签: macos swift3 line-breaks nstextview nsparagraphstyle

我有一个NSTextView来显示由标签分隔的长行数字数据。 我无法阻止固定长度后的换行。 作为测试。我用到字符串: 显示一长串纯文本A工作正常:
enter image description here
TextB在9个块之后断行: enter image description here 我的代码:(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的内容以获得没有标签的工作结果)

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

我找不到任何设置换行符的内容。我错过了什么?

0 个答案:

没有答案