UIView 职责(面向对象编程)

发布于 2025-01-06 06:58:27 字数 259 浏览 3 评论 0原文

我刚刚开始 iOS 应用程序开发,到目前为止这是一次很棒的经历。苹果文档很棒,但我有一些问题不是技术性的,只有有经验的人才能回答。

我有一堆 UIViewController 来处理它们控制的自定义 UIView 的“动态换肤”。这导致控制器包含大量代码,这对我来说似乎有点不切实际。

所以问题是:遵循 MVC 模式,我应该将设置 UIFont、UIColor 等的责任交给视图本身吗?或者我应该创建“微”控制器来使用某种输入来处理此任务?

感谢您的回复。

I am just starting out with iOS app development and it's been a great experience so far. Apple documentation is great, but there are some questions I have that are not as technical and only someone with experience might be able to answer.

I have a bunch of UIViewController which handle the "dynamic skinning" of the custom UIViews that they control. This leads to a controller with big chunks of code which seems a bit unpractical to me.

So the question is: Following the MVC pattern, should I give the responsibility of setting a UIFont, UIColor, etc to the view itself? Or should I create "micro" controllers that handle this task using some kind of input?

Thanks for the response.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

老子叫无熙 2025-01-13 06:58:27

创建处理布局工作的 UIView 子类。重写 UIView 子类中的 layoutSubviews 来进行定位布局(设置框架等)。我发现 init 方法是设置字体、颜色等的好地方。

现在 UIViewController 与自定义 UIView 相关的代码相对较少。 viewController 只需要定位自定义 UIView 的实例,并且可能设置一些属性(例如 textLabel 的文本)。

Creating UIView subclasses that handle the layout works. Override layoutSubviews in the UIView subclass to do the positioning layout (setting frames etc). I find the init method to be a good place to set fonts, colors etc.

Now the UIViewController has relatively little code related to the custom UIView. The viewController just needs to position an instance of the custom UIView and perhaps set a few properties (like a textLabel's text).

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