在Finder中,我发现在NSSearchfield第一次获得焦点时,取消按钮消失了,但是当我向搜索字段输入内容时,除非我单击它,否则取消按钮一直存在。我还手动创建了nssearchfield并输入了一些单词但是,当我逐个删除单词直到什么也没有删除时,最后,取消按钮消失了。它看起来像nssearchfield的默认行为,那么如何更改默认行为?
请帮忙,谢谢!
最佳答案
您可以直接访问取消按钮:
迅速
let searchField = NSSearchField()
// Change the button:
if let cell = searchField.cell as? NSSearchFieldCell,
let cancelButton = cell.cancelButtonCell {
// Here you can access all properties of a NSButtonCell
}
// Hide the button:
searchField.cell?.cancelButtonCell = nil
目标C
NSSearchField* searchField = [NSSearchField new]
// Change the button:
NSSearchFieldCell* cell = searchField.cell
NSButtonCell* cancelButton = cell.cancelButtonCell
if (cancelButton) {
// Here you can access all properties of a NSButtonCell
}
// Hide the button:
searchField.cell.cancelButtonCell = nil
关于macos - 如何更改NSSearchField中cancelbutton的行为?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14598505/