Uiview UIAppearance子视图将从导航栏中消失
我正在使用appdelegate中的外观对导航栏进行一些更改 这是我的方法:Uiview UIAppearance子视图将从导航栏中消失,uiview,navigationbar,uiappearance,Uiview,Navigationbar,Uiappearance,我正在使用appdelegate中的外观对导航栏进行一些更改 这是我的方法: -(void) setAppearance{ NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]]; [titleBarAttributes setValue:[UIFont f
-(void) setAppearance{
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:@"AvantGarde-ExtraLight" size:18] forKey:NSFontAttributeName];
[titleBarAttributes setValue:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:6.0/256.0 green:57.0/256.0 blue:84.0/256.0 alpha:1.0]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
int borderSize = 3;
UIImageView *navBorder = [[UIImageView alloc] initWithFrame:CGRectMake(0,
41,
320,
borderSize)];
navBorder.image = [UIImage imageNamed:@"energy_line"];
navBorder.tag = 999;
[[UINavigationBar appearance] addSubview:navBorder];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
我的appdelegate中有一个方法,它将窗口设置为我的第一个viewController,当我调用此方法时,我的navBorder将从导航栏中删除。我不明白为什么会发生这种情况,viewcontroller中的导航栏中没有更改任何内容的代码
- (void)rootView
{
[self.window setRootViewController:initialViewController];
}
我在这里回答了几乎相同的问题: 但这里有一个总结: 调用[[UINavigationBar外观]返回接收方类的外观代理。addSubview:方法未标记为UI_外观_选择器。UIApproxy方法的一个主要缺点是很难知道哪些选择器兼容 您应该控制导航栏并通过调用以下方法将图像添加到其中:
[self.navigationController.navigationBar addSubview:navBorder]
,或者您应该对UINavigationBar
进行子类化,这将为您提供更大的灵活性