iosobjective-cuiviewstoryboardautoresizingmask

Autoresizing Not Working Programmatically


I want to create a UIView which will resize it's width according to iPhone Screen size and it should be remain at bottom of view.

I created fresh project with storyboard and add below code.

Here is my code

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:true];

    UIView *box = [[UIView alloc]initWithFrame:CGRectMake(0, 448, 320, 120)];
    [box setBackgroundColor:[UIColor redColor]];

    [box setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    [box setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
    [box setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
    [box setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
    [box setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];

    [self.view addSubview:box];
}

Auto layout is OFF.

If I do same thing by apply autoresizing from interface builder then it's working perfectly.

I didn't understand any reason for why it's not working.


Solution

  • Little mistake from my side. My code is correct.

    The issue is related to xCode 6.1, in launch screen we have xib file from xCode 6 so i have to remove reference of it from General Setting-> App Icon and Launch Images and use Assert Catalog instead of launchscreen.xib and it start working....

    Anyway thanks for reply to my question.