在iOS中使用自定义导航栏

在iOS中使用自定义导航栏

本文介绍了在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?

推荐答案

听起来对我来说您可能实际上并不想使用。正如它在参考文档中所述:

It sounds to me that you may not actually want to use a UINavigationBar. As it states in the reference documentation:

因此,如果您计划的自定义设置不仅仅是添加按钮,还可以更改它的颜色/背景,不透明,隐藏等等。你可能最好创建一个感觉导航栏。

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.

以下是如何为。

它更灵活,实际上很容易做到但是你有很多阅读和测试在你面前:)。

It's far more flexible and actually quite easy to do BUT you've got alot of reading and testing ahead of you :).

如果它只是你想要添加的按钮,你可能最好使用而不是

Just in case if it's just buttons you're thinking of adding you might be better off using UIToolbar instead

这篇关于在iOS中使用自定义导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:22