开发者

UINavigationController barstyle property changes layout

开发者 https://www.devze.com 2023-04-01 21:26 出处:网络
I have a modal view controller which displays a navigation controller. The navigation controller in-turn has a regular UIViewController as its root view controller. The only UI element that the above-

I have a modal view controller which displays a navigation controller. The navigation controller in-turn has a regular UIViewController as its root view controller. The only UI element that the above-mentioned UIViewController has is a UISwitch.

Now here's the problem: When I change the barStyle property of the开发者_高级运维 navigation controller, the layout of the UISwitch inside the UIViewController changes. Here's what I am talking about:

If I don't set the barStyle property, here's what I get:

http://img535.imageshack.us/img535/2281/plaini.png

The UISwitch is now in its 'exepected' place.

Now if I set the barStyle property,

navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

Notice that the UISwitch is behind the navigation bar:

http://img853.imageshack.us/img853/2377/blackya.png

Here's the code for the UISwitch in the UIViewController:

- (void)viewDidLoad
{
    UISwitch* mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
    [self.view addSubview:mySwitch];
    [mySwitch release];
}

Can someone help me understand what's happening?


The Frame shifts when you use the UIBarStyleBlackTranslucent (which is actually deprecated) property because it assumes you want your view to be underneath

The Apple Documentation says to use the following since UIBarStyleBlackTranslucent is deprecated:

navController.navigationBar.barStyle = UIBarStyleBlack;
navController.navigationBar.translucent = YES;

You could try shifting your view back in the correct place or try using the following:

navController.navigationBar.tintColor = [UIColor blackColor];
navController.navigationBar.translucent = YES;
0

精彩评论

暂无评论...
验证码 换一张
取 消