如何创建一个使用 Touch Bar 剩余宽度的 NSTouchBarItem?

How do you create a NSTouchBarItem that uses the remaining width in the Touch Bar?

我正在尝试创建一个 NSButton,它占用 Touch Bar 上剩余的 space。我的目标是在 Safari 中有一个类似于 "Search or enter website name" 按钮的按钮。

我看过使用 widthAnchor 设置约束,但我完全不知道如何正确设置它。

NSButton 具有适合其内容的 intrinsicContentSize,默认值 horizontal contentHuggingPriority 为 750 (NSLayoutPriorityDefaultHigh),这意味着它将强烈尝试匹配该内容宽度。

你可以decrease that hugging priority(例如[button setContentHuggingPriority:1.0 forOrientation:NSLayoutConstraintOrientationHorizontal])为了让它更能拉伸远离那个内容,在这种情况下填充额外的space在触摸酒吧.