除了 titleView 之外,还向 UINavigationBar 添加标签
我正在使用 UINavigationController 来推送我的视图。我想在根视图控制器的 UINavigationBar 中的标题上方添加一个 UILabel。
当我使用以下代码时,标签会出现,但位于 UINavigationBar 下方:
[self.view addSubview:newLabel];
有没有办法将标签添加到 UINavigationBar 或 UIView 中,以便它显示在导航栏上方?
我知道我可以创建一个新的 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];
但是,这是否违背了使用导航控制器的目的?
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.
When I use the following code, the label appears, but under the 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?
I know I can create a new UINavigationBar and build it with multiple controls like this:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以参考这个网站,也许它可以帮助您解决问题
http://iphonesdevsdk。 blogspot.com/2011/04/uinavigationbar.html
You can refer this site, may be it help you in sorting your problem
http://iphonesdevsdk.blogspot.com/2011/04/uinavigationbar.html