xcode 将 CGcolorRef 转换为 UIColor
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10050059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert CGcolorRef to UIColor
提问by Mc.Lover
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
我想知道如何转换CGcolorRef
为UIColor
?我为自己创建了一个自定义方法,我需要它来使用 UIColor
EDITED method :
编辑方法:
- (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];
but is there any way to use only UIColor?
但是有没有办法只使用 UIColor?
回答by Conrad Shultz
Does + (UIColor *)colorWithCGColor:(CGColorRef)cgColor
not do what you need?
难道+ (UIColor *)colorWithCGColor:(CGColorRef)cgColor
不是你所需要的?
Follow-up:
跟进:
Try implementing your method as something like:
尝试将您的方法实现为:
- (void)setFontColor:(UIColor *)color forString(NSString *)aString {
[coreTextLayer setForegroundColor:[color CGColor]];
...
}
(Adjusted to be more in line with Cocoa naming conventions, and to not use dot syntax. ;-)
(调整为更符合 Cocoa 命名约定,并且不使用点语法。;-)
回答by Xval
Why don't you use
你为什么不使用
- (UIColor *)initWithCGColor:(CGColorRef)cgColor
- (UIColor *)initWithCGColor:(CGColorRef)cgColor