実現したいこと
可変サイズのウィンドウでtoolbarにtextfieldを横いっぱいに広げたい
発生している問題
画像のようにtextFeild(searchField)のAutoresizingを設定しても一定のサイズを超えたら止まってしまう
該当のソースコード
storyboardメインのためgithubにあげてます
https://github.com/masakichi41/swift-sample1
試したこと
- storyboardのtoolbarItemの最小サイズと最大サイズを設定する
特に動作は変わらず下記の警告メッセージが出力されました。
NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
windowWillResize
でminSize
を動的に変更する
swift:WindowController.swift
1import Cocoa 2 3class WindowController: NSWindowController, NSWindowDelegate { 4 @IBOutlet weak var toolbarItem: NSToolbarItem! 5 6 func windowWillResize(_ sender: NSWindow, to frameSize: NSSize) -> NSSize { 7 toolbarItem.minSize.width = frameSize.width - 86 8 return frameSize 9 } 10} 11
期待通り動作しますが下記の警告メッセージが出力されました。
'minSize' was deprecated in macOS 12.0: This property is no longer recommended. Instead, let the system automatically measure the size of the view using constraints.
非推奨となったものは使いたくないので別の方法を模索しているところです。
ご教授いただけたら幸いです。
よろしくお願いします。
補足情報
MacOS 13.1
Xcode 14.2
Swift 5.7.2
アプリ対応バージョンMacOS 12.0~
あなたの回答
tips
プレビュー