从模态视图设置导航控制器并在界面生成器中设置布局?
我正在尝试从模态视图设置导航控制器,但我不知道如何使用界面生成器设置布局选项。这是我正在使用的代码。
//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 选项,这对我来说会更容易,鉴于此,这可能吗设置?
I'm trying to set up a NavigationController from a Modal View, but I can't figure out how to set the layout options using interface builder. Here's the code I'm using.
//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];
Is there anyway to set the layout options of the navigationcontroller in interface builder? I tried setting the color using
nav.navigationBar.tintColor = [UIColor colorWithRed:128 green:0 blue:0 alpha:1];
but that results in a bright red instead of the maroon color this RGB combination is supposed to result in.
It would be much easier for me if I could control the NavigationController options from interface builder, is this possible given this setup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您是以编程方式创建这些视图,因此无需在界面生成器中设置任何内容。但是,您可以通过编程方式设置色调颜色。您的问题是 UIColor 初始值设定项采用 1.0f 和 0.0f 之间的浮点来表示颜色强度。你的 128 只是被限制在 1.0f,因此是亮红色。试试这个:
这应该会给你一个更接近你想要的颜色。
Since you are creating these views programmatically, there's nothing to set in interface builder. You can, however, programmatically set the tint color. Your problem is that the UIColor initializer takes floats between 1.0f and 0.0f for the intensity of the color. Your 128 is simply clamped to 1.0f, hence bright red. Try this instead:
That should give you a color closer to what you're looking for.
您无法使用界面生成器更改色调颜色。您必须对其进行硬编码,就像您在问题中暗示的那样。
你有两个选择。
alpha
值来获取 Maroon,然后使用它。(使用 Paint 或 Photoshop)
,并将其设置为您的背景视图。
You cannot change the tint color using the interface builder. You will have to hard code it, just like you had implied in your question.
You have two options.
alpha
to get Maroon and then use it.(using paint or photoshop)
, and set that as yourbackground view.