OSX: How do you allow user to resize window under auto layout?

Jody Hagins

I have a NSWindow, with some views, hooked together with auto layout constraints.

Window looks something like this...

Label - TextView - Label - TextView - Label - DatePicker

Label - TextView - Label - PopUp - Label - PopUp

The data for the popups is obtained via bindings to core data, so the values are not known until runtime. I want those controls to resize to accommodate the values from the database.

On the surface, everything seems to be fine. However, if I end up with a really long string in a popup control, the size of that control causes the size of the window to expand.

I want the sizes to be dynamic, and change according to the values of the data, but I want the constraints to be limited to the size of the window.

However, I want the user to be able to resize the window, if they want to make it wider. I only want the window to be resized by the user (the window size will be saved and restored automatically).

I sort of get that if I set the hugging value on the main view of the window, but that seems to prevent the user from being able to resize the window as well. If I reduce the priority of the controls' constraints, I don't get the size and positioning as I want it.

So, basically, I want the controls to change as the window size changes, but I don't want the size of the window to change unless to user changes it. How can I get that to happen?

Thanks!

Ken Thomases

You will need to change the content hugging and compression resistance priorities of your views to be less than NSLayoutPriorityWindowSizeStayPut (500).

If the content hugging priorities are higher than that, then the window won't be able to be resized to be so large that those views get stretched. If the compression resistance priorities are higher than that, then the window won't be able to be resized to be so small that those views get compressed.

You say "[i]f [you] reduce the priority of the controls' constraints, [you] don't get the size and positioning as [you] want it". Well, what breaks? You'll need to find a way to achieve what you want even with the content hugging and compression resistance priorities reduced.

You may want to put minimum width constraints on your views, too, to prevent the window from compressing them to nothing. Collectively, such constraints will establish the minimum size for your window (which you probably do want).

Also, you probably want the priorities to be different among the views or you'll get ambiguity and somewhat arbitrary results. That is, if the user shrinks the window so not everything can fit, and if two or more views have the same compression resistance priority, then it will be arbitrary which is compressed. It can even flip back and forth disconcertingly as further changes are made. So, you should effectively nominate which should compress first, then second, etc., by ordering their compression resistance priorities. Similarly for content hugging.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mac OS X use auto layout with view controller and allow window resize

From Dev

Mac OS X use auto layout with view controller and allow window resize

From Dev

How do you allow only one instance of an inherited window to be open?

From Dev

NSScrollView with auto layout not resizing until first manual window resize

From Dev

How do I resize views when keyboard pops up using Auto Layout

From Dev

Resize Uiview with Auto Layout

From Dev

dynamic Auto Layout resize

From Dev

How do you resize an AVFrame?

From Dev

How do I optimize image auto-adjustment on window resize and init

From Dev

How do I keep the individual controls on a custom user control from spreading out (and still allow resize)

From Dev

How do you re-size Facebook plugin comment (fb-comments) with angular on window resize?

From Dev

How to resize Window to dimension in VIew Controller for a OSX app?

From Dev

How do you change terminal font size in OSX withOUT changing the terminal window size as well?

From Dev

How do you change terminal font size in OSX withOUT changing the terminal window size as well?

From Dev

Resize Xcode window on OSX 10.9

From Dev

Resize Xcode window on OSX 10.9

From Dev

How do I make the javascript resize event handler happen only after the user stops resizing the window?

From Dev

How can I align and resize these two elements with Storyboard Auto Layout?

From Dev

How to resize a fixed width and height UIImageView with auto layout

From Dev

How to make a square view resize with its superview using auto layout

From Dev

How to resize a fixed width and height UIImageView with auto layout

From Dev

How do you define the vertical and horizontal relationship between views using the Masonry DSL for Auto Layout?

From Dev

Auto resize linear layout with textview

From Dev

How to make an image auto resize to fit browser window with relation to height

From Dev

How do I resize a WebDriverJS browser window?

From Dev

How to do something on window resize in Vala?

From Dev

How to do something on window resize in Vala?

From Dev

How do you put tabs under another layout similar to the Google+ app? (Example Pic Incuded)

From Dev

Auto expand div on window resize

Related Related

  1. 1

    Mac OS X use auto layout with view controller and allow window resize

  2. 2

    Mac OS X use auto layout with view controller and allow window resize

  3. 3

    How do you allow only one instance of an inherited window to be open?

  4. 4

    NSScrollView with auto layout not resizing until first manual window resize

  5. 5

    How do I resize views when keyboard pops up using Auto Layout

  6. 6

    Resize Uiview with Auto Layout

  7. 7

    dynamic Auto Layout resize

  8. 8

    How do you resize an AVFrame?

  9. 9

    How do I optimize image auto-adjustment on window resize and init

  10. 10

    How do I keep the individual controls on a custom user control from spreading out (and still allow resize)

  11. 11

    How do you re-size Facebook plugin comment (fb-comments) with angular on window resize?

  12. 12

    How to resize Window to dimension in VIew Controller for a OSX app?

  13. 13

    How do you change terminal font size in OSX withOUT changing the terminal window size as well?

  14. 14

    How do you change terminal font size in OSX withOUT changing the terminal window size as well?

  15. 15

    Resize Xcode window on OSX 10.9

  16. 16

    Resize Xcode window on OSX 10.9

  17. 17

    How do I make the javascript resize event handler happen only after the user stops resizing the window?

  18. 18

    How can I align and resize these two elements with Storyboard Auto Layout?

  19. 19

    How to resize a fixed width and height UIImageView with auto layout

  20. 20

    How to make a square view resize with its superview using auto layout

  21. 21

    How to resize a fixed width and height UIImageView with auto layout

  22. 22

    How do you define the vertical and horizontal relationship between views using the Masonry DSL for Auto Layout?

  23. 23

    Auto resize linear layout with textview

  24. 24

    How to make an image auto resize to fit browser window with relation to height

  25. 25

    How do I resize a WebDriverJS browser window?

  26. 26

    How to do something on window resize in Vala?

  27. 27

    How to do something on window resize in Vala?

  28. 28

    How do you put tabs under another layout similar to the Google+ app? (Example Pic Incuded)

  29. 29

    Auto expand div on window resize

HotTag

Archive