如何使NSTextView随文本一起增长? [英] How do I make NSTextView grow with text?
问题描述
我正在创建一个简单的文字处理器,用户可以在其中向NSView
添加一个文本框,类似于Pages中的功能.问题在于,无论用户输入多少文本,添加时它将保持相同的大小.我希望它随着用户输入文本的增长而增长,我已经尝试过使用
I am creating a simple word processor where it's possible for the user to add a text box to an NSView
, similar to the function in Pages. The problem is that when it's added it will stay the same size no matter how much text the user inputs. I want it to grow as the user inputs text, I have tried with this GitHub project but when I use it the text field only expands when I have deleted all the text, as if the code doesn't react before the textDidEndEditing
method. After working a bit with NSTextView
I found that it would be more suitable for the task, but I still can't make it work. I'm running Mavericks and Xcode 5.0.1.
希望有人可以帮助我!
Hope someone can help me!
推荐答案
This example fixed it for me: https://developer.apple.com/library/mac/documentation/cocoa/conceptual/TextUILayer/Tasks/TextInScrollView.html
您必须将其放入NSScrollView中.行为与UITextView中的行为不同(如果您具有iOS背景).
You have to put it into a NSScrollView. The behavior is not the same as in UITextView (if you have a iOS background).
这篇关于如何使NSTextView随文本一起增长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!