Xcode: how to re-arrange elements not auto-moved to the center? - xcode

When I try to re-arrange the elements in Xcode 4.2 interface builder (put something as a subview of another etc.) it places elements in the center, not preserving it's current position.
Is it possible to re-arrange the elements in Interface Builder with preserving their position in main UIView?

It's not entirely possible to rearrange elements in the way you want. The best you can do is to select one or more elements and choose Editor > Embed In > View. That will put the selected elements in a new UIView without changing the on-screen position of the elements. But the new UIView will not tightly wrap the embedded elements.

Related

How to make NSSearchField take up whole width of toolbar

I am trying to make a NSSearchField taking up the whole width of a toolbar in a NSWindowController.
I created a new NSWindowController using Xcode storyboard, add a toolbar to it, when add search field to the toolbar.
I drag the search field from allowed toolbar items to default toolbar items
Set toolbar item's max width to a large number say 1000
I build the app and run. The search field shrinks when window width shrinks, but does not expand beyond a certain width when window width expands.
The question is how to make search field expand and take up all remaining space of the toolbar?
It doesn't sound to me like the toolbar is really what you want to use here. The purpose of the toolbar is to allow multiple UI elements to be included in a user-configurable way. If you want to force one element that takes up the entire width, I suggest just putting it in the window's content view and setting up the layout constraints to pin to both the left and right sides. If you set the "Textured" check box in Interface Builder, it should look roughly the same as it would have looked using the toolbar.

Xcode UI how to get the corresponding storyboard element?

What is the short cut to get the correspondign storyboard elements when selecting one of the black dots on the left of the code interface?
Simply click on that black dot, you can see the corresponding storyboard element. By selecting that, you can go directly to that particular view.

How to assign different z-order to my Interface Builder objects?

How can I change the z-value, or just send to back or to front the objects in Interface Builder?
i.e. I would like to move to front the "Label" in this View:
You need to reorder then in Interface Builder. It seems like you're using Xcode 4. So, first, click on the arrow in the bottom left corner of IB to expand the side panel:
Next, click and drag the views that you'd like to rearrange.
The lower an item is on the list from the top of the list, the higher its "z-index".
with that object selected, goto (menu) Editor>Arrangement> . There will be 4 options with activated appropriate options.
xCode 10.3 (2019):
I had the same problem when copying/pasting a background image view. I couldn't drag it to change its z-order in the Document Outline panel (in Interface Builder).
The answer was just to restart xCode.
I think that re-indexed/re-built the storyboard and I could drag it higher in the list (thus making it lower in the z-order + behind the other controls).

NSSplitter how to prevent proportional space distribution on resize

I have a window with a source list sidebar at the right side and a content view on the left both inside an NSSplitView.
When i resize the window, the additional space is distributed to the source list and the content view. How can i make the source list to maintain its fixed width. All Apple applications are doing this so i hope i just missed a method.
On SnowLeopard, there is a delegate method called splitView:shouldAdjustSizeOfSubview:. All you have to do is return NO for your source list view, and you should be good. If you need to support Leopard or earlier, you have to implement splitView:resizeSubviewsWithOldSize: and manually resize the subviews, keeping your source list view a fixed width, and resizing your other view to fill the split view's bounds (taking into account the divider's width).
Both methods are documented here

Sizing a control to fit its container in Interface Builder

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?
I've done this, the way Jon Hess mentions first. Assuming you're using Interface Builder version 3:
Drag and resize your GUI (tableview from what I understand?) component to fit into the enclosing area the way you want it.
Click it to select it.
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".
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.
Turn all six things on, making them red.
VoilĂ  :-)
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.
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.
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.

Resources