Search code examples
iphoneiosautoresizeautoresizingmask

Trouble with autoresizingMask and fixed margins


I'm trying to get this to work with code in a ViewController's view:

alt text

but I can't get it to work.

I've tried

-(void)loadView {
    UIView *contentView = [[[UIView alloc] init] autorelease];
    self.view = contentView;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(5,5,0,100);
    button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [contentView addSubview:button];
}

but the width of the button is still the width of the superview...

I'm sure there's an easy explanation.

Thanks, everybody!

Antonio


Solution

  • -initWithFrame: is the designated initializer for UIView. On the Mac side (NSView) I know strange things can happen when using -init instead of -initWithFrame:. Perhaps this is the problem?