的默认宽度NSSearchToolbarItem
太大。我希望它类似于 Notes 应用程序。
有没有官方的方法可以做到这一点?
该控件有一个 property preferredWidthForSearchField
,但这没有任何作用,这也可能是 Big Sur 的许多 bug 之一。
经典但已弃用的minSize
设置maxSize
似乎可以工作,但随后控件失去了根据可用工具栏空间自动调整自身大小的能力。
的默认宽度NSSearchToolbarItem
太大。我希望它类似于 Notes 应用程序。
有没有官方的方法可以做到这一点?
该控件有一个 property preferredWidthForSearchField
,但这没有任何作用,这也可能是 Big Sur 的许多 bug 之一。
经典但已弃用的minSize
设置maxSize
似乎可以工作,但随后控件失去了根据可用工具栏空间自动调整自身大小的能力。
也许不是最好的方法,但这似乎有效:
searchToolbarItem.searchField.addConstraint(NSLayoutConstraint(item: searchToolbarItem.searchField, attribute: .width, relatedBy: .lessThanOrEqual, toItem: nil, attribute: .width, multiplier: 1, constant: 200) )
searchToolbarItem.searchField.addConstraint(NSLayoutConstraint(item: searchToolbarItem.searchField, attribute: .width, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: .width, multiplier: 1, constant: 30) )