我有一个基于导航控制器的应用标签,
导航栏中的标题在该标签的根页中显示正常,
但是当我在顶部推另一个视图控制器时,无法为该视图设置标题
这是我用于根页面和推送页面的代码,
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *lava = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]autorelease];
lava.backgroundColor = [UIColor clearColor];
lava.text = @"About us";
lava.textAlignment = UITextAlignmentCenter ;
lava.textColor = [UIColor whiteColor];
lava.font = [UIFont fontWithName:@"DroidSans-Bold" size:(46)];
lava.shadowColor = [UIColor blackColor];
lava.shadowOffset = CGSizeMake(2, 3);
self.navigationItem.titleView = lava;
}
因此,在导航栏上设置我的标题缺少什么?
谢谢!
最佳答案
您可以尝试self.navigationController.navigationItem.titleView
或者,如果您使用iOS5或更高版本。
UIImage *img=[UIImage imageNamed:@"NavBarBackground.png"];
[self.navigationController.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:18.0f],UITextAttributeFont
,[UIColor whiteColor],UITextAttributeTextColor
,[UIColor blackColor],UITextAttributeTextShadowColor
,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)],UITextAttributeTextShadowOffset
, nil];
[self.navigationController.navigationBar setTitleTextAttributes:dict];
在rootViewController的
viewDidLoad
中调用一次,然后就可以在任何地方使用self.title=@"foo"
了。关于ios - iOS导航标题未显示在子页面上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11293281/