Sizing a control to fit its container in Interface Builder

∥☆過路亽.° 提交于 2020-01-24 12:50:06

问题


Let's say I have a split view, and I want to fill half of it with a table view (a fairly common use case, I would think). Is there any way to tell the table view to size itself to fit the split view or do I really have to size it manually?


回答1:


As far as I know, doing it manually is the only way to go. However, if you turn on "snap to cocoa guidelines", the inner view will snap to the edges of the enclosing view as you drag towards them. This makes it easier than having to manually mouse the edges into place, or manually edit the sizes to match.




回答2:


I've done this, the way Jon Hess mentions first. Assuming you're using Interface Builder version 3:

  1. Drag and resize your GUI (tableview from what I understand?) component to fit into the enclosing area the way you want it.

  2. Click it to select it.

  3. Press Command-Shift-I to open the inspector window for this GUI component. The inspector window should now actually show that you've selected a "Scroll View".

  4. Click the "ruler" heading to be able to set the sizing. You'll see to the right an animated representation of how your GUI component will behave within its enclosing GUI component, and to the left another represenation of the same, without animation, but with four springs and two struts that you can turn on or off.

  5. Turn all six things on, making them red.

Voilà :-)




回答3:


It's generally easier to create the subviews first, then use the Layout/Embed Objects In/Split View menu item to create the split view around them.




回答4:


You can set all of the springs and struts of the table view to "on" in the size inspector and that will cause the table view to fill the split view. Alternatively, you can use the outline view in the main document window to place the tableview's enclosing scroll view directly into the splitview instead of in an intermediary custom view.



来源:https://stackoverflow.com/questions/342082/sizing-a-control-to-fit-its-container-in-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!