本文介绍了将CGcolorRef转换为UIColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何将 CGcolorRef
转换为 UIColor
?我为自己创建了一个自定义方法,我需要它来使用UIColor
I was wondering how can convert CGcolorRef
to UIColor
? I have created a custom method for my own and I need it to use UIColor
EDITED方法:
- (void)fontColor:(CGColorRef)colors setString(NSSTring *)blah blah blah {
coreTextLayer.foregroundColor = color;
}
[myClass fontColor:[UIColor redColor] setString....];
正确的方法是这样使用:
the right way is use something like this :
[UIColor redColor]CGColor];
但有没有办法只使用UIColor?
but is there any way to use only UIColor?
推荐答案
+(UIColor *)colorWithCGColor:(CGColorRef)cgColor
不能满足您的需求吗?
Does + (UIColor *)colorWithCGColor:(CGColorRef)cgColor
not do what you need?
跟进:
尝试将您的方法实现为:
Try implementing your method as something like:
- (void)setFontColor:(UIColor *)color forString(NSString *)aString {
[coreTextLayer setForegroundColor:[color CGColor]];
...
}
(调整后更符合Cocoa命名约定,不使用点语法。; - )
(Adjusted to be more in line with Cocoa naming conventions, and to not use dot syntax. ;-)
这篇关于将CGcolorRef转换为UIColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!