【问题标题】:Set up NavigationController from Modal View and set layout in interface builder?从模态视图设置 NavigationController 并在界面构建器中设置布局?
【发布时间】:2012-02-05 05:51:40
【问题描述】:

我正在尝试从模态视图设置 NavigationController,但我不知道如何使用界面生成器设置布局选项。这是我正在使用的代码。

 //Create the view you want to present modally
 UIViewController *modalView = [[UIViewController alloc] init];
 //Create a new navigation stack and use it as the new RootViewController for it
 UINavigationController *nav = [[UINavigationController alloc]          
 initWithRootViewController:modalView];
 //Present the new navigation stack modally
 [self presentModalViewController:nav animated:YES];
 //Release
 [modalView release];
 [nav release];

是否可以在界面生成器中设置导航控制器的布局选项?我尝试使用

设置颜色
nav.navigationBar.tintColor = [UIColor colorWithRed:128 green:0 blue:0 alpha:1];

但这会产生鲜红色而不是这种 RGB 组合应该产生的栗色。

如果我可以从界面生成器中控制 NavigationController 选项,这对我来说会容易得多,在这种设置下这可能吗?

【问题讨论】:

  • 您只能在 IB 的主视图中设置导航栏的色调颜色。如果要更改视图之间的色调,则必须对其进行硬编码。

标签: iphone xcode uinavigationcontroller interface-builder modalviewcontroller


【解决方案1】:

您无法使用界面生成器更改色调颜色。您将不得不对其进行硬编码,就像您在问题中暗示的那样。

你有两个选择。

  1. 使用RGB值,alpha的不同值得到Maroon,然后使用它。
  2. 创建栗色背景(using paint or photoshop),并将其设置为您的background view.

【讨论】:

    【解决方案2】:

    由于您是以编程方式创建这些视图,因此无需在界面生成器中设置任何内容。但是,您可以以编程方式设置色调颜色。您的问题是 UIColor 初始化程序采用 1.0f 和 0.0f 之间的浮点数来表示颜色的强度。你的 128 被简单地夹在 1.0f,因此是鲜红色的。试试这个:

    nav.navigationBar.tintColor = [UIColor colorWithRed:0.5f blue:0 green:0 alpha:1.0f];
    

    这应该让您的颜色更接近您正在寻找的颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-07
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      • 2011-07-13
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多