Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert CGcolorRef to 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 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?

like image 972
iOS.Lover Avatar asked Apr 06 '12 22:04

iOS.Lover


2 Answers

Does + (UIColor *)colorWithCGColor:(CGColorRef)cgColor not do what you need?


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. ;-)

like image 102
Conrad Shultz Avatar answered Nov 15 '22 16:11

Conrad Shultz


Why don't you use

  • (UIColor *)initWithCGColor:(CGColorRef)cgColor
like image 38
Xval Avatar answered Nov 15 '22 17:11

Xval