はじめに
frame(minWidth:idealWidth:maxWidth:minHeight:idealHeight:maxHeight:alignment:)
を設定することでウインドウサイズを固定できると思っていたらできなくてつまづいたので記録しておきます。
私の認識では以下のようにすれば1番大きい時で110、1番小さい時で100になると思ってました。
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
}
.frame(minWidth: 100, maxWidth: 110, minHeight: 100, maxHeight: 110)
}
}
frame
が機能していません
やりかた
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
}
.frame(minWidth: 100, maxWidth: 110, minHeight: 100, maxHeight: 110)
}
}
import SwiftUI
@main
struct macos_window_size_sampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
+ .windowResizability(.contentSize)
}
}
おわり
最近macOSアプリを作ることが多いので新たな発見があって楽しいです
参考記事