开发者

How to disable resizing of the subview of NSSplitView in Interface Builder?

I've created in Interface Builder a NSSplitView with two subviews. I want the left-side view to have fixed width. I've tried to define autosizing rules for both subviews but the left subview still changes width on window resizing (split view fills up a window). May be that caused by NSSplitView's Autoresizes Subviews property? (I can't uncheck it). What c开发者_运维问答an I do?


The best way I found to do this in Interface Builder:

  • Drop the NSSplitView on the window
  • Select the Custom View you want fixed
  • Go up to the Xcode menu and select Editor > Pin > Width
  • Adjust the Constant in the Attributes Inspector to the size that you want the panel to be fixed at

Of course, you can also add this layout constraint through code as suggested above if you're feeling adventurous.


The behavior that you want required some code that you can do on the NSSplitView's delegate. However, you can have the same result using BWToolKit.


I think it should work with a NSLayoutConstraint, I work at the moment on at :).

EDIT:

Maybe to provide more details on my answer based on the comment hayden. You can define a constraint either by code or in the the IB. In the IB select your left subview and click on the constraint buttons in the lower right corner defining a width constraints. If you select this new constraint now you can setup the the width an say it should be equal and set the size you like.

The seconed way is to create in code a NSLayoutConstraint object, i do it like this (this is just an example, and define not a fix width).

// define for the view: Constraint and AutoresizingMask option
NSView *view = self.view;
[view setTranslatesAutoresizingMaskIntoConstraints:NO];  // disable AutoresizingMask
NSDictionary *views = NSDictionaryOfVariableBindings(view);
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[view(>=140,<=220)]" options:0 metrics:nil views:views]];

In general you find documentation to this topic under the term Auto Layout. To use it you have to enable auto layout and this featuer replace the old autosizing functions. (therefore i disable autosizing mask in the code).

This feature is quit new and you can do complex stuff with it but i think I is worth to study.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜