我正在尝试像这样更改文本视图中制表符的宽度:
let paragraph = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paragraph.tabStops.removeAll()
// Set the tab width to 4 spaces wide
paragraph.defaultTabInterval = CGFloat(4) * (" " as NSString).size(withAttributes: [.font: font]).width
// set text view's typing attributes, default paragraph style, etc w/ this style
这成功地修改了制表符的宽度,但在整个文档中插入了制表位。我期待的是:
text = "" // Visually: ""
// Insert tab
text = "\t" // Visually: "----" 4 long
// With some other characters before
text = "abc" // Visually: ""
// Insert tab
text = "abc\t" // Visually: "abc----" 4 long in addition to abc
我实际看到的是:
text = "abc" // Visually: ""
// Insert tab
text = "abc\t" // Visually: "abc-" 4 long in total
文档中似乎还有一些制表位,但我不知道它们可能来自哪里。