本文介绍了在iOS 7和Objective c中使用UIColor类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIColor + MyLayout.m文件,例如:

I have a UIColor+MyLayout.m file such as:

@implementation UIColor (Layout)

- (UIColor *) textBackground
{
    UIColor *lightGreen = [UIColor colorWithRed:0.0f/255.0f green:178.0f/255.0f     blue:238.0f/255.0f alpha:1.0f];

    return lightGreen;
}

@end

我添加了.h文件到我的viewcontroller.m,但如何将其调用为UIColor?

I have added the .h file to my viewcontroller.m, but how do I call this into a UIColor?

UIColor * myColor =?

UIColor *myColor = ?

推荐答案

如果您执行以下操作会更好:

Would be better if you do the following:

@implementation UIColor (Layout)

+ (UIColor *) textBackground {
    UIColor *lightGreen = [UIColor colorWithRed:0.0f/255.0f green:178.0f/255.0f        blue:238.0f/255.0f alpha:1.0f];
    return lightGreen;
}

@end

然后只需将其称为 UIColor * myColor = [UIColor textBackground];

这篇关于在iOS 7和Objective c中使用UIColor类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 09:32