Languages such as Japanese or Chinese can be written vertically, starting from the top right of the page, going down, and when you reach the bottom, you go up and go to the next line on the left.
NSTextView
seems to support this out of the box with
textView.setLayoutOrientation(.vertical)
There is also a storyboard option.
While this seems to work for a single text view (the text does begin on the top right of the text view), it doesn't work when I try to make the text view scrollable, putting the text view inside a scroll view.
For example, when I tried to add a "Scrollable Text View" in the storyboard, the NSTextView
doesn't fill the whole scroll view for some reason, as indicated by the little white squares in the picture:
(Note that the only constraints I added was pinning the four edges of the scroll view to the window)
This is undesirable. The text view should fill the whole scroll view, so that the text begins on the very right of the window. The text view doesn't expand to the at all when I drag the right side of the window to expand it.
The text view only expands when I enter more text in it.
None of these behaviours can be seen if the text view has horizontal orientation.
What am I doing wrong? Is scrollable vertical text just not supported?
I've also tried adding the text view programmatically, but the same behaviour shows up
let scrollView = NSTextView.scrollableTextView()
view.addSubview(scrollView)
scrollView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: view.topAnchor),
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
scrollView.leftAnchor.constraint(equalTo: view.leftAnchor),
scrollView.rightAnchor.constraint(equalTo: view.rightAnchor),
])
let textView = scrollView.documentView as! NSTextView
textView.textStorage?.setAttributedString(
NSAttributedString(string: "あいうえおかきくえこ", attributes: [
.font: NSFont.systemFont(ofSize: 25),
.foregroundColor: NSColor.textColor
])
)
textView.setLayoutOrientation(.vertical)