{"id":9114,"date":"2022-02-04T21:10:08","date_gmt":"2022-02-04T21:10:08","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=9114"},"modified":"2022-02-05T16:21:40","modified_gmt":"2022-02-05T16:21:40","slug":"swiftui-why-is-my-mac-window-not-resizable","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/swiftui-why-is-my-mac-window-not-resizable\/","title":{"rendered":"SwiftUI &#8211; why is my Mac window not resizable?"},"content":{"rendered":"<p>As a newbie to SwiftUI, I was surprised to find my simple little sample application would not resize. If you&#8217;re used to WPF, WinForms and even other non-Windows user interface libraries, you&#8217;ll notice by default the windows are usually resizable. So what&#8217;s the deal with SwiftUI<\/p>\n<p>So my code looked like this<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nvar body: some View {\r\n   VStack {\r\n      Text(viewModel.title)\r\n         .padding()\r\n      TextField(&quot;Enter&quot;, text: $viewModel.title)\r\n   }\r\n   .padding()\r\n   .frame(minWidth: 500, minHeight: 300)\r\n}\r\n<\/pre>\n<p>Simple enough, display a text label and input text field.<\/p>\n<p>So what&#8217;s the problem, why is the Man window not resizable?<\/p>\n<p><strong>Spacer<\/strong><\/p>\n<p>The <a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/spacer\" rel=\"noopener\" target=\"_blank\">Spacer<\/a> is key here. If we change the code to the following, the it all starts to work as I wanted<\/p>\n<pre class=\"brush: csharp; highlight: [6]; title: ; notranslate\" title=\"\">\r\nvar body: some View {\r\n   VStack {\r\n      Text(viewModel.title)\r\n         .padding()\r\n      TextField(&quot;Enter&quot;, text: $viewModel.title)\r\n      Spacer()\r\n   }\r\n   .padding()\r\n   .frame(minWidth: 500, minHeight: 300)\r\n}\r\n<\/pre>\n<p>The Spacer expands to fill space. <\/p>\n<p>If you have a Spacer within a VStack the spacer fills space on the vertical and if on an HStack it fills horizontally. But the above code will expand on both the vertical and horizontal. In this case the TextField seems to combine with the Spacer to allow both the axis to expand.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a newbie to SwiftUI, I was surprised to find my simple little sample application would not resize. If you&#8217;re used to WPF, WinForms and even other non-Windows user interface libraries, you&#8217;ll notice by default the windows are usually resizable. So what&#8217;s the deal with SwiftUI So my code looked like this var body: some [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[287],"tags":[],"class_list":["post-9114","post","type-post","status-publish","format-standard","hentry","category-swiftui"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=9114"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9114\/revisions"}],"predecessor-version":[{"id":9131,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9114\/revisions\/9131"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}