Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIColor扩展_Ios_Objective C_Iphone_Uicolor - Fatal编程技术网

Ios UIColor扩展

Ios UIColor扩展,ios,objective-c,iphone,uicolor,Ios,Objective C,Iphone,Uicolor,我在objective-c中扩展了UIColor类 头文件如下所示: @interface UIColor (ColorDecision) + (UIColor*) directOrLegacyWithColor; + (UIColor*) changeColor; @end #define Color_C7 [SharedUtility colorWithHexString:@"FF6A00"] // orange #define Color_Dire

我在objective-c中扩展了UIColor类 头文件如下所示:

@interface UIColor (ColorDecision)
+ (UIColor*) directOrLegacyWithColor;
+ (UIColor*) changeColor;
@end
#define Color_C7           [SharedUtility colorWithHexString:@"FF6A00"] // orange
#define Color_Direct      [Utility colorWithHexString:@"313d53"] // Color for direct
实施:

#import "UIColor+ColorDecision.h"

@implementation UIColor (ColorDecision)
 + (UIColor *)directOrLegacyWithColor {
     UIColor *color;
     UIColor *returenedColor = self.changeColor;
     color = LoginsManager.getSharedInstance.isDirect ? returenedColor : [UIColor self];
     return color;
}

 + (UIColor *)changeColor{
     UIColor *newColor;
     if (self == Color_C7) newColor = Color_Direct;

     return newColor;
}
@end
我从“类”的下面一行“分配给“UIColor*”的不兼容指针类型”得到编译器的警告

我知道问题出在与指针的关系上,但我不知道该怎么办

编辑 感谢manishharma93注释,我现在解决了第一个问题,当我想使用指定的方法时,这些方法似乎不可见

我在全局头文件中定义了我的颜色,如下所示:

@interface UIColor (ColorDecision)
+ (UIColor*) directOrLegacyWithColor;
+ (UIColor*) changeColor;
@end
#define Color_C7           [SharedUtility colorWithHexString:@"FF6A00"] // orange
#define Color_Direct      [Utility colorWithHexString:@"313d53"] // Color for direct
这是实用程序类中“colorWithHexString”函数的实现:

+(UIColor *)colorWithHexString:(NSString *)hexString {
NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString];
CGFloat alpha, red, blue, green;
switch ([colorString length]) {
    case 3: // #RGB
        alpha = 1.0f;
        red   = [SharedUtility colorComponentFrom: colorString start: 0 length: 1];
        green = [SharedUtility colorComponentFrom: colorString start: 1 length: 1];
        blue  = [SharedUtility colorComponentFrom: colorString start: 2 length: 1];
        break;
    case 4: // #ARGB
        alpha = [SharedUtility colorComponentFrom: colorString start: 0 length: 1];
        red   = [SharedUtility colorComponentFrom: colorString start: 1 length: 1];
        green = [SharedUtility colorComponentFrom: colorString start: 2 length: 1];
        blue  = [SharedUtility colorComponentFrom: colorString start: 3 length: 1];
        break;
    case 6: // #RRGGBB
        alpha = 1.0f;
        red   = [SharedUtility colorComponentFrom: colorString start: 0 length: 2];
        green = [SharedUtility colorComponentFrom: colorString start: 2 length: 2];
        blue  = [SharedUtility colorComponentFrom: colorString start: 4 length: 2];
        break;
    case 8: // #AARRGGBB
        alpha = [SharedUtility colorComponentFrom: colorString start: 0 length: 2];
        red   = [SharedUtility colorComponentFrom: colorString start: 2 length: 2];
        green = [SharedUtility colorComponentFrom: colorString start: 4 length: 2];
        blue  = [SharedUtility colorComponentFrom: colorString start: 6 length: 2];
        break;
    default:
        LOG(@"WARNING: tried to set color from string: %@ BUT string should be  a hex value of the form #RBG, #ARGB, #RRGGBB, or #AARRGGBB ", hexString);
        return nil;
        break;
}
return [UIColor colorWithRed: red green: green blue: blue alpha: alpha];
}
现在,当我想使用我的扩展函数时,例如: self.background=Color_C7。直接与颜色搭配 “directOrLegacyWithColor”功能不可见

在您的方法中,请将“self”更改为“[UIColor self]”


将“self”更改为“[UIColor self]”。警告意志go@manishsharma93问题解决了,谢谢。但是现在我有另一个问题,当我想使用例如Color_C7。directOrLegacyWithColor方法“directOrLegacyWithColor”不可见。是否可以使用Color_C7和Color_Direct的值更新答案。这样我就很容易找到原因了。我会写上面的评论作为回答,如果它解决了你的问题,请接受。我接受了你的答案,但在编辑中我添加了另一个one@taratandel谢谢你的回答。但我认为您无法访问宏上的UIColor类方法。因此,您可以做的是,创建一个UIColor对象并将值放入其中,例如,UIColor*color=[UIColor director egacyWithColor];。然后你可以随意使用这些颜色我可以这样做吗?+(UIColor*)director egacywithcolor:(UIColor*)color{UIColor*newColor;UIColor*returenedColor=self.changeColor:color;newColor=LoginsManager.getSharedInstance.isDirect?returenedColor:[UIColor-self];return newColor;}+(UIColor*)changeColor:(UIColor*)color*)color{UIColor*newColor;if(self==color\u C7)newColor=Color\u Direct;返回newColor;}是。试着这样做。我仍然得到一个错误:“struct objc_class”中没有名为“changeColor”的成员