【问题标题】:Add a label to UINavigationBar in addition to the titleView除了titleView之外,给UINavigationBar添加一个标签
【发布时间】:2011-04-02 18:14:22
【问题描述】:

我正在使用 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];

但是,这不是违背了使用导航控制器的目的吗?

【问题讨论】:

    标签: xcode uinavigationcontroller uinavigationbar


    【解决方案1】:

    你可以参考这个网站,也许它可以帮助你解决你的问题

    http://iphonesdevsdk.blogspot.com/2011/04/uinavigationbar.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 2022-11-13
      相关资源
      最近更新 更多