子类化 UINavigationController 的步骤
我想对 UINavigationController 进行子类化,以获得有关控制器外观的更多自由。
我有一些不同部分、栏、按钮、文本等的图形。 查看 UINavigationController 头文件我几乎没有得到任何帮助,我不知道从哪里开始。
我以前从未子类化/重写过 UIKit 组件,看起来有点像玩夏洛克·福尔摩斯。
方法是什么?
我如何知道要重写什么才能将特定的图形“注入”正确的位置?
我是否需要子类化 UINavigationBar, UIBarButtonItem 等以获得完整的自定义外观?
我如何知道某些内容是否受到 Apple 批准的限制?
希望有人能给我指出正确的方向,我只能找到更改控制器小部分的示例,而不能通过子类化进行完全自定义。 我是否以错误的方式处理这个问题?
谢谢:)
I would like to subclass the UINavigationController to get some more freedom in regards to the appearance of the controller.
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.
I have never subclassed/overridden a UIKit component before, it seems it is a bit like playing Sherlock Holmes.
What is the approach?
How do I know what to override to get a a specific piece of graphics "injected" the correct place?
Do I need to subclass UINavigationBar, UIBarButtonItem etc. etc to get the complete customized look?
How do I know if something is off limits in regards to being approved by 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?
Thanks:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在您可以子类化 UINavigationController,请参阅更新的文档:
UINavigationController 类参考
Now you can subclass UINavigationController, see updated documentation:
UINavigationController Class Reference
您不应该扩展 UINavigationController。
从 iOS 6 开始,此信息已过时。来自 Xcode 5 文档:
您通常按原样使用此类,但在 iOS 6 及更高版本中,您可以创建子类来自定义类行为。
原始过时信息如下:
来自文档:
您可能需要考虑创建类别或对 UINavigationBar 进行子类化,并可能创建用于创建 UIBarButtonItems 的自定义 UIButton。
每当您处理从 UIView 扩展的 UI 组件时,您应该考虑做的是子类化和重写。
stackoverflow 或 Apple 的官方文档网站上有很多示例。
You should NOT extend UINavigationController.
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.
Original outdated information follows:
From the documentation:
You may want to consider creating categories or subclassing your UINavigationBar and potentially creating custom UIButtons that you use to create UIBarButtonItems.
Whenever you deal with a UI component that extends from UIView what you should consider doing is subclassing and overriding
There are plenty of examples here on stackoverflow or on Apple's official documentation site.