1

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.

coneybeare
  • 33,113
  • 21
  • 131
  • 183
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434

3 Answers3

4

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]];
Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
0

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.

coneybeare
  • 33,113
  • 21
  • 131
  • 183
0

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]
Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150