Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Iphone 将CGcolorRef转换为UIColor_Iphone_Objective C_Ios_Xcode - Fatal编程技术网

Iphone 将CGcolorRef转换为UIColor

Iphone 将CGcolorRef转换为UIColor,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我想知道如何将CGcolorRef转换为UIColor?我已经为自己创建了一个自定义方法,我需要它来使用UIColor 编辑方法: - (void)fontColor:(CGColorRef)colors setString(NSSTring *)blah blah blah { coreTextLayer.foregroundColor = color; } [myClass fontColor:[UIColor redColor] setString...

我想知道如何将
CGcolorRef
转换为
UIColor
?我已经为自己创建了一个自定义方法,我需要它来使用UIColor

编辑方法:

    - (void)fontColor:(CGColorRef)colors setString(NSSTring *)blah blah blah  {

    coreTextLayer.foregroundColor = color;


    }


[myClass fontColor:[UIColor redColor] setString....];
正确的方法是使用如下内容:

[UIColor redColor]CGColor];
但是有没有办法只使用UIColor?

难道
+(UIColor*)colorWithCGColor:(CGColorRef)cgColor
不能满足您的需要吗


后续行动:

尝试实现您的方法,如:

- (void)setFontColor:(UIColor *)color forString(NSString *)aString  {
    [coreTextLayer setForegroundColor:[color CGColor]];
    ...
}
(调整为更符合Cocoa命名约定,并且不使用点语法。;-

为什么不使用

  • (UIColor*)initWithCGColor:(CGColorRef)cgColor

ammm实际上不仅仅是UIColor,我的方法是这样的:
-(void)fontColor:(CGColorRef)colors setString(NSSTring*)诸如此类{
很抱歉,我不明白您在这里想要实现什么。我写的东西会返回给定CGColorRef的UIColor。您担心什么?尽管您更新的代码似乎让您想走相反的方向,即,
[[UIColor REDCLOR]CGColor]
。是的,我是这样使用它的,但有没有可能只使用UIColor?请参阅我的更新答案,其中CGColor被降级为内部实现细节。