在iOS中使用自定义导航栏 [英] Use custom Navigation Bar in iOS
问题描述
我在.xib中添加了一个导航栏。
我这样做是因为我想定制很多东西。我希望我的导航控制器在该屏幕中使用该导航栏。
I added a Navigation Bar to the .xib. I did that because I want to customize a lot of things of it. I want my navigation controller to use that navigation bar in that screen.
我创建了一个名为navBar的插座并做了:
I created the outlet named navBar and did:
[self.navigationController.navigationBar = navBar;
但它表示navigationBar是只读的。是否可以将我现有的导航控制器与我添加到屏幕的导航栏相关联?
But it says that navigationBar is readonly. Is it possible to link my existing navigation controller with the navigation bar that I added to the screen?
推荐答案
听起来对我来说您可能实际上并不想使用 UINavigationBar 。正如它在参考文档中所述:
It sounds to me that you may not actually want to use a UINavigationBar. As it states in the reference documentation:
UINavigationBar类实现用于导航分层内容的控件。它是一个条形图,通常显示在屏幕顶部,包含用于在层次结构中上下导航的按钮。主要属性是左(后)按钮,中心标题和可选的右按钮。您可以为每个选项指定自定义视图。
The UINavigationBar class implements a control for navigating hierarchical content. It’s a bar, typically displayed at the top of the screen, containing buttons for navigating up and down a hierarchy. The primary properties are a left (back) button, a center title, and an optional right button. You can specify custom views for each of these.
因此,如果您计划的自定义设置不仅仅是添加按钮,还可以更改它的颜色/背景,不透明,隐藏等等。你可能最好创建一个 UIView 感觉导航栏。
So if you're planned customizations go beyond adding buttons, changing it's color / background, opacity, hiding etc.. you might be better off creating a UIView that mimics the look & feel of a navigation bar.
以下是如何为您的UIView提供导航渐变外观的示例酒吧。
它更灵活,实际上很容易做到但是你有很多阅读和测试在你面前:)。
It's far more flexible and actually quite easy to do BUT you've got alot of reading and testing ahead of you :).
如果它只是你想要添加的按钮,你可能最好使用 UIToolbar 而不是
Just in case if it's just buttons you're thinking of adding you might be better off using UIToolbar instead
这篇关于在iOS中使用自定义导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!