NSView 调整大小
我有一个 NSView ,其中有一个 NSTextField 。问题是,每次显示视图之前, NSTextField 的大小都会改变,我希望 NSView 的大小也随之改变。因此,如果文本字段有 2 行长,则 nsview 会很小(只是勉强包围文本字段),但是当其长度为 10 行时,我不希望视图的大小切断文本字段,我希望视图随之增长。
我怎样才能做到这一点?谢谢。
I have an NSView with a NSTextField in it. The problem is, each time before displaying the view, the size of the NSTextField can change and I want the size of NSView to change with it. So if textfield is 2 lines long, the nsview will be small (just barely surround the textfield) but when its 10 lines long, I don't want the view's size to cut off the textfield, i want the view to grow with it.
How can I do that? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我在表格视图中使用的,但它应该同样适用于您的情况:
希望有帮助!
This is what I use in my tableview, but it should apply equally to your situation:
Hope that helps!
您需要设置“contentHugging 和 contentCompression”优先级。
简而言之:
苹果在这里有一个参考:
https:// developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html
具体向下滚动到
设置内容拥抱和压缩阻力优先级
部分。这就是处理文本字段等...剪切(即当文本字段具有“某些 testValue”变为“某些 testV ...”等时...
Your need to set the "contentHugging and contentCompression" priorities.
In short:
Apple have a reference here:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html
Specifically scroll down to the
Setting Content-Hugging and Compression-Resistance Priorities
section.This is what deals with textFields etc... clipping (i.e. when a textfield has "some testValue" becomes "some testV..." etc...