4

There is a section in size inspector with name Atosizing that can set left,right,up,down layout of a control,i find that i do that with setAutoresizingMask but don't know how set it that my control layout to right and up (means when user resize window my control steak to right and up)

1 Answers1

12

Look at these -setAutoresizingMask parameters:

NSViewNotSizable

The receiver cannot be resized.

NSViewMinXMargin

The left margin between the receiver and its superview is flexible.

NSViewWidthSizable

The receiver’s width is flexible.

NSViewMaxXMargin

The right margin between the receiver and its superview is flexible.

NSViewMinYMargin

The bottom margin between the receiver and its superview is flexible.

NSViewHeightSizable

The receiver’s height is flexible.

NSViewMaxYMargin

The top margin between the receiver and its superview is flexible.


So You can do it like this:

[YourOutlet setAutoresizingMask: NSViewMinXMargin | NSViewMinYMargin];
Justin Boo
  • 10,132
  • 8
  • 50
  • 71
  • so if i want to set my control fix to right and top i should use `[btn setAutoresizingMask: ~NSViewMaxXMargin & ~NSViewMinYMargin];` but with this code my control disappear and i change `&` to `|` but again my control disappear –  Apr 29 '12 at 09:06
  • @sZSzsZ try to remove ~. With Max and min You will fix to left. Try mine min min. – Justin Boo Apr 29 '12 at 09:20
  • i test all of states (Min,Max,~,..) but my control doesn't fix –  Apr 29 '12 at 09:32
  • @sZSzsZ But with all states your control changes? or not? Maybe You forgot to Outlet *Btn*? – Justin Boo Apr 29 '12 at 09:52
  • Then show my how You doing in code or create sample project and send me, I will check it. – Justin Boo Apr 29 '12 at 20:26
  • `NSButton *btn=[[NSButton alloc]init]; btn.frame=CGRectMake(x+2, 0, 70, 70); btn setImage:[NSImage imageNamed:@"AddUser"]]; [btn setAutoresizingMask: …]; [myView addSubview:btn];` –  Apr 30 '12 at 05:17
  • You adding button as Your custom View's subview so Your button moves how Your View can move, if You want to control Your button's autoresizing add to Window's view like this `[[windowOutlet contentView] addSubview:btn];`. (windowOutlet is Your main window *IBOutlet*) – Justin Boo Apr 30 '12 at 05:38
  • i need to add it to a view (view that i add in code) what should i do now? –  Apr 30 '12 at 08:49
  • Hmm.. You can use `-setAutoresizesSubview` but I don't think that this will help You. So I suggest to create new View inside MainWindow's View with buttons size and autoresize it. It's hard to understand why You can't do it without NSView. **Or You can place Your button to right top corner of Your current View and enable resize to right and up and width sizable (ALL FOR VIEW) than it should work.** I can't imagine how to do it otherwise. – Justin Boo Apr 30 '12 at 09:27
  • Hi guys i have got a problem I have some code that says "[_indicatorView setAutoresizingMask:63];" Can you help me understand what this means. – Taranmeet Singh Aug 19 '14 at 07:57
  • 1
    @Taranmeet setting autoresizing mask to 63 means that all parameters are on. It's shorter than write every parameter in line. – Justin Boo Aug 19 '14 at 08:32