susitha
susitha

Reputation: 467

How to adjust the toolbar according to the ipad orientation

I added a toolbar for an ipad application programatically.

     UIToolbar *drawToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,710 , 1024, 40)];
     [self.view addSubview:drawToolBar];
     [drawToolBar release];

Now it is shown in the bottom of the ipad screen, when in the landscape mode. it comes in to the middle,when it is in the portrait mode. How can i put it, always in the bottom.

Upvotes: 0

Views: 313

Answers (2)

Mak
Mak

Reputation: 46

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) )
    {

        UIToolbar *drawToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,708 , 1024, 40)];
 [self.view addSubview:drawToolBar];
 [drawToolBar release];

    }
    else if (interfaceOrientation == UIInterfaceOrientationPortrait ||  interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        UIToolbar *drawToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,964 , 768, 40)];
 [self.view addSubview:drawToolBar];
 [drawToolBar release];

}
return YES;
}

Upvotes: 1

Pfitz
Pfitz

Reputation: 7344

UIView has an property called autoresizingMask there you can set your struts and springs like in interface builder.

Here is the documentation: UIView class reference on autoresizingMask

Upvotes: 1

Related Questions