子类化 UINavigationController 的步骤

发布于 2024-09-05 19:15:11 字数 495 浏览 5 评论 0原文

我想对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看海 2024-09-12 19:15:11

现在您可以子类化 UINavigationController,请参阅更新的文档:

UINavigationController 类实现了一个专门的视图控制器,用于管理分层内容的导航。此导航界面可以有效地呈现您的数据,也使用户可以更轻松地导航该内容。该类通常按原样使用,但可能在 iOS 6 及更高版本中进行子类化。

UINavigationController 类参考

Now you can subclass UINavigationController, see updated documentation:

The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and also makes it easier for the user to navigate that content. This class is generally used as-is but may be subclassed in iOS 6 and later.

UINavigationController Class Reference

热血少△年 2024-09-12 19:15:11

您不应该扩展 UINavigationController。

从 iOS 6 开始,此信息已过时。来自 Xcode 5 文档:
您通常按原样使用此类,但在 iOS 6 及更高版本中,您可以创建子类来自定义类行为。

原始过时信息如下:

来自文档:

UINavigationController 类实现了一个专门的视图控制器,用于管理分层内容的导航。该类不适合子类化。相反,当您希望应用程序的用户界面反映内容的层次结构性质时,您可以按原样使用它的实例。

您可能需要考虑创建类别或对 UINavigationBar 进行子类化,并可能创建用于创建 UIBarButtonItems 的自定义 UIButton。

每当您处理从 UIView 扩展的 UI 组件时,您应该考虑做的是子类化和重写。

- (void)drawRect:(CGRect)rect

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:

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.

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

- (void)drawRect:(CGRect)rect

There are plenty of examples here on stackoverflow or on Apple's official documentation site.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文