UIView 职责(面向对象编程)
我刚刚开始 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建处理布局工作的 UIView 子类。重写
UIView
子类中的layoutSubviews
来进行定位布局(设置框架等)。我发现init
方法是设置字体、颜色等的好地方。现在
UIViewController
与自定义 UIView 相关的代码相对较少。 viewController 只需要定位自定义 UIView 的实例,并且可能设置一些属性(例如 textLabel 的文本)。Creating
UIView
subclasses that handle the layout works. OverridelayoutSubviews
in theUIView
subclass to do the positioning layout (setting frames etc). I find theinit
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).