开发者

Making a utilities class for frequently used colors etc in app

I am making a u开发者_运维问答tilities 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.


Instead of a subclass I use a UIColor category for custom colors

something like this:

@implementation UIColor (CustomColors)

+ (UIColor *)mb_toolBarTintColor {
    return [UIColor colorWithHue:0.5 saturation:0.1 brightness:0.3 alpha:1];
}

@end

and then I can use it with a simple

[self.toolBar setTintColor:[UIColor mb_toolBarTintColor]];


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.


You can also simply make a .h file that has a bunch of #define values for constants, such as:

#define TEXT_COLOR [UIColor colorWithRed:0.8f green:0.8f blue:0.8f alpha:1.0f]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜