2011-04-15 14 views

回答

4

而不是一个子类的我使用的UIColor类别自定义颜色

是这样的:

@implementation UIColor (CustomColors) 

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

@end 

,然后我可以用一个简单的

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

忘了一件事,我需要导入UIKit或这个类别,我将使用它吗? – LuckyLuke 2011-04-15 18:08:56

0

子类总是需要导入super。使您的子类成为UIColor的直接子类,然后在.h文件中导入超类或整个工具包。

0

你也可以用它只需制作一个.h文件,该文件具有一堆用于常量的#define值,例如:

#define TEXT_COLOR [UIColor colorWithRed:0.8f green:0.8f blue:0.8f alpha:1.0f] 
相关问题