我需要以编程方式制作一些标签和文本字段.我可以到达那里.
//create the file name label
NSTextField* newFileNameLabel = [[NSTextField alloc] initWithFrame:NSMakeRect(objXPos, objYPos, 300.0, 20.0)];
//set properties
[newFileNameLabel setBordered: NO];
[newFileNameLabel setTextColor: [NSColor whiteColor]];
[newFileNameLabel setDrawsBackground:NO];
[newFileNameLabel setEditable:NO];
[newFileNameLabel setStringValue: @"File Name:"];
[vSheetView addSubview:newFileNameLabel];
Run Code Online (Sandbox Code Playgroud)
但我在文档中找不到任何可以让我设置wrap属性的东西.在IB中,属性是布局,其中包含'scroll,wrap和truncate'作为选项.NSTextField没有设置它的方法,如果我上传继承链也没有NSControl.NSView有一个setNeedsLayout方法,但似乎没有相关性:
You only ever need to invoke this method if your view implements custom layout
not expressible in the constraint-based layout system by overriding the layout method.
The system invokes this method automatically for all views using constraints for layout.
Run Code Online (Sandbox Code Playgroud)
NSTextFieldCell也没有任何方法.任何帮助,将不胜感激.
小智 9
在OS X 10.11和Swift 2.1中,以下内容帮助了我:
multilineLabel.lineBreakMode = .ByWordWrapping
multilineLabel.setContentCompressionResistancePriority(250, forOrientation: .Horizontal)
Run Code Online (Sandbox Code Playgroud)
如果使用AutoLayout,则需要设置抗压性.
这对我有用:
textField.usesSingleLineMode = false
textField.cell?.wraps = true
textField.cell?.scrollable = false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6196 次 |
| 最近记录: |