xcode 除了 titleView 之外,还向 UINavigationBar 添加标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5524975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add a label to UINavigationBar in addition to the titleView
提问by Lauren Quantrell
I'm using a UINavigationController to push my views. I want to add a UILabel above the title in the UINavigationBar of the root view controller.
我正在使用 UINavigationController 来推送我的视图。我想在根视图控制器的 UINavigationBar 的标题上方添加一个 UILabel。
When I use the following code, the label appears, but under the UINavigationBar:
当我使用以下代码时,标签出现,但在 UINavigationBar 下:
[self.view addSubview:newLabel];
Is there a way to add the label to the UINavigationBar or to the UIView so that it appears above the navigation bar?
有没有办法将标签添加到 UINavigationBar 或 UIView 以便它出现在导航栏上方?
I know I can create a new UINavigationBar and build it with multiple controls like this:
我知道我可以创建一个新的 UINavigationBar 并使用多个控件构建它,如下所示:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
navBar.barStyle = UIBarStyleBlack;
navBar.translucent = YES;
[self.view addSubview:navBar];
[navBar release];
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,8,280,30)];
navLabel.text = @"My Text";
[navBar addSubview:navLabel];
[navLabel release];
However, doesn't that defeat the purpose of using the navigation controller?
然而,这不是违背了使用导航控制器的目的吗?
采纳答案by Anand
You can refer this site, may be it help you in sorting your problem
你可以参考这个网站,也许它可以帮助你解决你的问题
http://iphonesdevsdk.blogspot.com/2011/04/uinavigationbar.html
http://iphonesdevsdk.blogspot.com/2011/04/uinavigationbar.html