我在objective中扩展了UIColor类,头文件如下所示:
@interface UIColor (ColorDecision)
+ (UIColor*) directOrLegacyWithColor;
+ (UIColor*) changeColor;
@end执行情况:
#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*”从“类”分配给“*”。
color = LoginsManager.getSharedInstance.isDirect ? returenedColor : [UIColor self];我知道问题与指针有多大的关系,但我不知道该怎么做。
编辑
由于manishharma93注释,我现在解决了第一个问题,当我想要使用指定的方法时,这些方法似乎是不可见的。
我在全局头文件中定义了颜色,如下所示:
#define Color_C7 [SharedUtility colorWithHexString:@"FF6A00"] // orange
#define Color_Direct [Utility colorWithHexString:@"313d53"] // Color for direct这是Utility中'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 'directOrLegacyWithColor‘函数不可见
发布于 2019-08-01 13:08:59
在您的方法中,将"self“改为"UIColor self”。
+ (UIColor *)directOrLegacyWithColor {
UIColor *color;
UIColor *returenedColor = self.changeColor;
color = LoginsManager.getSharedInstance.isDirect ? returenedColor : [UIColor self];
return color;
}https://stackoverflow.com/questions/57309329
复制相似问题