我想继承 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 组件,这似乎有点像玩福尔摩斯.
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 的自定义 UIButtons.
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 的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!