Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ATG

macrumors regular
Original poster
Aug 7, 2005
187
0
I've got a NSView that I'm inserting into another NSView that is in a nib file using:
Code:
- (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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
If we assume your sub view and superview then this will more or less work (typed straight into Safari):

Code:
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

macrumors regular
Original poster
Aug 7, 2005
187
0
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
ATG said:
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

macrumors regular
Original poster
Aug 7, 2005
187
0
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.