子类化UINavigationController的步骤 [英] Steps in subclassing UINavigationController
问题描述
我想继承UINavigationController以获得更多关于控制器外观的自由。
I would like to subclass the UINavigationController to get some more freedom in regards to the appearance of the controller.
我有一些图形用于不同的部分,条形图,按钮,文本等。
查看UINavigationController头文件我得到的帮助不大,我不知道从哪里开始。
I have some graphics for the different parts, bars, buttons, text etc. Looking at the UINavigationController header file I get little help, I don't know where to start out.
我从未进行过子类化/之前覆盖了UIKit组件,似乎有点像玩Sherlock Holmes。
I have never subclassed/overridden a UIKit component before, it seems it is a bit like playing Sherlock Holmes.
方法是什么?
我如何知道要覆盖什么来获取特定的图形注入正确的位置?
我是否需要继承UINavigationBar,UIBarButtonItem等子类以获得完整的自定义外观?
我如何知道是否关于被Apple批准的事情是不允许的?
希望有人能指出我正确的方向,我只能找到考试更改控制器的小部分,而不是通过子类化完全自定义。
我这样做错了吗?
Hope someone can point me in the right direction, I have only been able to find examples of changing small parts of the controller, not a full customization by subclassing. Am I going about this the wrong way?
谢谢:)
推荐答案
您不应该扩展UINavigationController。
You should NOT extend UINavigationController.
从iOS 6开始,此信息已过时。来自Xcode 5文档:
您通常使用此类原样,但在iOS 6及更高版本中,您可以继承自定义类行为。
As of iOS 6, this information is outdated. From the Xcode 5 docs: You generally use this class as-is but in iOS 6 and later you may subclass to customize the class behavior.
原始过时的信息如下:
来自文档:
UINavigationController类实现了一个管理的专用视图控制器分层内容的导航。此类不适用于子类。相反,在希望应用程序的用户界面反映内容的层次性的情况下,您可以按原样使用它的实例。
The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This class is not intended for subclassing. Instead, you use instances of it as-is in situations where you want your application’s user interface to reflect the hierarchical nature of your content.
您可能需要考虑创建类别或子类化UINavigationBar并可能创建用于创建UIBarButtonItems的自定义UIBut。
You may want to consider creating categories or subclassing your UINavigationBar and potentially creating custom UIButtons that you use to create UIBarButtonItems.
每当您处理从UIView扩展的UI组件时您应该考虑做的是子类化和重写
Whenever you deal with a UI component that extends from UIView what you should consider doing is subclassing and overriding
- (void)drawRect:(CGRect)rect
stackoverflow或Apple官方文档网站上有很多例子。
There are plenty of examples here on stackoverflow or on Apple's official documentation site.
这篇关于子类化UINavigationController的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!