为应用程序中常用的颜色等创建实用程序类
我正在制作一个实用程序类,该类在其他常用代码中具有一些返回颜色的方法。然而 UIColor 类是 UIKit 的一部分,所以我想知道我应该将 UIKit 导入到 NSObject 的这个子类中,还是应该返回一个 id ?或者还有其他选择吗?
提前致谢。
I am making a utilities class that among other frequently used code have some methods for returning colors. However UIColor
class is a part of UIKit so I wonder should I import UIKit to this subclass of NSObject, or should I return an id
? Or are there other options?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用 UIColor 类别来代替子类来自定义颜色,
如下所示:
然后我可以将它与简单的
Instead of a subclass I use a UIColor category for custom colors
something like this:
and then I can use it with a simple
子类总是需要导入父类。让您的子类成为
UIColor
的直接子类,然后导入超类或 .h 文件中的整个套件。A subclass always needs to import the super. Make your subclass a direct subclass of
UIColor
, and then import the superclass, or the entire kit in the .h file.您还可以简单地创建一个 .h 文件,其中包含一堆 #define 常量值,例如:
You can also simply make a .h file that has a bunch of #define values for constants, such as: