首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >子页面上未显示iOS导航标题

子页面上未显示iOS导航标题
EN

Stack Overflow用户
提问于 2012-07-02 20:01:09
回答 4查看 1.9K关注 0票数 2

我有一个基于导航控制器的应用程序标签,

导航栏中的标题在选项卡的根页面中显示良好,

但是,当我在顶部推入另一个视图控制器时,我无法设置此视图的标题

这是我用于根页面和推送页面的代码,

代码语言:javascript
复制
- (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;

 }

那么,在导航栏上设置我的标题缺少什么呢?

谢谢!

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-07-02 20:20:29

你可以试试self.navigationController.navigationItem.titleView

或者如果您使用iOS5或更高版本..

代码语言:javascript
复制
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"了。

票数 1
EN

Stack Overflow用户

发布于 2012-07-02 20:15:10

您应该在新的控制器viewDidLoad中更改标题

票数 1
EN

Stack Overflow用户

发布于 2012-07-02 20:23:08

代码语言:javascript
复制
CGRect applicationFrame = CGRectMake(0, 0, 300, 40);
UIView * newView = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
[newView addSubview: lava];
self.navigationItem.titleView = newView;

试着这样做。我想这对你会有帮助的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11293281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档