PDA

View Full Version : Making a view fill its superview




ATG
Jul 26, 2006, 01:19 PM
I've got a NSView that I'm inserting into another NSView that is in a nib file using:
- (void)addSubview:(NSView *)aView

That all goes fine and it appears in the IB NSView perfectly. However the subview is stuck to point (0, 0) in the superview when I want it to fill the whole of the superview. I've tried setting the 'springs and struts' of just about everything in IB but it still won't fill the whole view (the subview does resize, it just doesn't fill the whole superview).

Does anybody know how to solve this? I'll post my app/code if wanted.

Thanks :)



robbieduncan
Jul 26, 2006, 02:18 PM
If we assume your sub view and superview then this will more or less work (typed straight into Safari):


NSView *subview = ...
NSView *superview = ...

[superview addSubview:subview];
NSRect frame = [subview frame];
NSRect superFrame = [superview frame];
frame.size.width = superFrame.size.width;
frame.size.height = superFrame.size.height;
[subview setFrame:frame];

ATG
Jul 26, 2006, 04:12 PM
Thanks! :)

I can't test it right now because I'm too tired but tomorrow I will put it in my code.

Would that live resize the subview as the window is resized so that it is always filling the superview whatever size the window?

robbieduncan
Jul 26, 2006, 04:16 PM
Thanks! :)

I can't test it right now because I'm too tired but tomorrow I will put it in my code.

Would that live resize the subview as the window is resized so that it is always filling the superview whatever size the window?

No. It simply sets the size when you add it. You should still use the springs and struts to control the auto-sizing behaviour.

ATG
Jul 27, 2006, 09:21 AM
Just put it in and it works fine :) There is one interface element that isn't apprearing but I think that's just a spring or strut that I havn't set right.

Thanks :D