以编程方式在UINavigationController中设置UINavigationBar的自定义子类

问题描述:

有人知道如果我以编程方式实例化UINavigationController的情况下(不使用IB)如何使用我的UINavigationBar的自定义子类?

Does anyone know how can I use my custom subclass of UINavigationBar if I instantiate UINavigationController programmatically (without IB)?

在IB中拖动一个UINavigationController会在导航栏下显示一个,并使用Identity Inspectory我可以更改类类型并设置自己的UINavigationBar子类,但是通过编程我不能这样做,导航控制器的navigationBar属性是只读的...

Drag a UINavigationController in IB show me an under Navigation Bar and using Identity Inspectory I can change class type and set my own subclass of UINavigationBar but programmatically I can't, navigationBar property of Navigation Controller is readonly...

我该怎么做才能以编程方式自定义导航栏? IB比代码"更强大"吗?我相信在IB中可以做的所有事情都可以通过编程来完成.

What should I do to customize the navigation bar programmatically? Is IB more "powerful" than "code"? I believed all that can be done in IB could be done also programmatically.

您不需要仅仅使用KVC就可以破坏XIB.

You don't need to muck with the XIB simply use KVC.

[self.navigationController setValue:[[[CustomNavBar alloc]init] autorelease] forKeyPath:@"navigationBar"];