Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 更改NSTextfield和多行文本的可编辑性_Swift_Macos_Resize_Osx Elcapitan_Nstextfield - Fatal编程技术网

Swift 更改NSTextfield和多行文本的可编辑性

Swift 更改NSTextfield和多行文本的可编辑性,swift,macos,resize,osx-elcapitan,nstextfield,Swift,Macos,Resize,Osx Elcapitan,Nstextfield,我有一个NSTextField,根据应用程序是处于编辑模式还是视图模式,它可以用作标签或可编辑文本字段 更改文本字段可编辑性的代码为: var editable : Bool = false { didSet { if editable { titleTextField?.editable = true titleTextField?.bezeled = true titleTextField?.dr

我有一个
NSTextField
,根据应用程序是处于编辑模式还是视图模式,它可以用作标签或可编辑文本字段

更改文本字段可编辑性的代码为:

var editable : Bool = false {
    didSet {
        if editable {
            titleTextField?.editable = true
            titleTextField?.bezeled = true
            titleTextField?.drawsBackground = true
            titleTextField?.cell?.usesSingleLineMode = false
            titleTextField?.cell?.wraps = true
            editButton?.state = NSOnState
        } else {
            titleTextField?.editable = false
            titleTextField?.bezeled = false
            titleTextField?.drawsBackground = false
            titleTextField?.cell?.usesSingleLineMode = false
            titleTextField?.cell?.wraps = true
            editButton?.state = NSOffState
        }
    }
}

@IBAction func editButtonPushed(sender : NSButton) {
    if sender.state == NSOnState {
        self.editable = true
    }else{
        self.editable = false
    }
}
我已将Interface Builder中的
NSTextField
定义为可编辑,并且未选择“使用单行模式”。文本字段位于自定义视图中,该视图是
NSSplitView
中的右视图。自定义视图还包含一个按钮,用户可以使用该按钮切换编辑模式(它连接到上述代码中的操作)

当文本字段中的标题较长(即多行)时,可编辑文本字段中将正确显示标题。当我单击编辑按钮(打开编辑模式)时,文本字段将变为不可编辑(上面的else语句)

问题在于,在非编辑模式下,
NSTextField
(以及父自定义视图)会调整大小,以便完整的标题可以放在一行的
NSTextField
(现在是标签)中。我希望文本字段保持相同大小,并使用两行显示标题


如何防止文本字段的大小调整?我尝试过使用
titleTextField?.cell?.usesSingleLineMode=false
titleTextField?.cell?.wrapps=true
,但这两种解决方案都不起作用。

您使用的是自动布局还是自动调整大小掩码?我使用的是自动布局。您能描述一下您的自动布局约束吗?