0

我尝试自定义我的 UINavigationBarController:

// Customize NavBar Appearance
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor clearColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],
                                                       NSFontAttributeName: [UIFont fontWithName:@"Lato-Light" size:35.0]}];

// Set NavBar Bottom Border to White by adding a view with height 1
UINavigationController *navBarController = [[self.tabBarController viewControllers] objectAtIndex:0];
CGFloat navBarWidth = navBarController.navigationBar.frame.size.width;

UIView *navBottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0, kNavBarHeight- 1, navBarWidth, 1)];
[navBottomBorder setBackgroundColor:[UIColor colorWithWhite:255.0f alpha:0.25f]];
[navBottomBorder setOpaque:YES];

[[UINavigationBar appearance] addSubview:navBottomBorder];

我遇到的问题是,当点击我的标签栏项目时,这个添加的子视图会随机消失。有时它完美可见,有时只显示文本和字体颜色的外观设置。顺便说一句:这些总是正确的。在第一次启动和切换选项卡后,只有我的子视图不再显示。

4

1 回答 1

0

当我使用“insertSubview”而不是“addSubview”时,它似乎可以工作。所以我可以想象,导航栏正在绘制在我添加的子视图上?

于 2013-11-12T22:34:40.090 回答