简体   繁体   English

根据字符串值调整NSTextField内容大小

[英]Adjust NSTextField content size based on the string value

In my project I am using NSTextField. 在我的项目中,我正在使用NSTextField。 As my application supports multiple languages, The same text field may have different text lengths according to various languages. 由于我的应用程序支持多种语言,根据不同的语言,相同的文本字段可能具有不同的文本长度。 Is there any option to solve this using auto lay out, setting constraints, or is there any property for the text field to adjust automatically according to the text. 是否有使用自动布局,设置约束来解决此问题的选项,或文本字段是否具有根据文本自动调整的任何属性。 Any help is appreciated. 任何帮助表示赞赏。

To get the "fitted" size used by the text view after it's updated its text, call usedRectForTextContainer: on the textView's layoutManager property, passing the textView's textContainer property as an argument. 若要获取文本视图更新后的文本的“适合”大小,请在usedRectForTextContainer:layoutManager属性上调用usedRectForTextContainer: ,并将usedRectForTextContainer:textContainer属性作为参数传递。

Autoresize textView: 自动调整textView的大小:

[myTextView sizeToFit];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM