Convert UIColor to CGColor in Fast

This is the Obj-C code:

CGContextSetStrokeColorWithColor(context, [[UIColor lightGrayColor] CGColor]); 

How to write it to swift.

+63
objective-c colors swift uicolor swift-converter
Jan 07 '15 at 2:36
source share
2 answers
 // Original answer. var newColor = UIColor.lightGrayColor().CGColor // Swift 3 version var newColor = UIColor.lightGray.cgColor 
+191
Jan 07 '15 at
source share
โ€” -

Oddly enough, since Swift evolved to 3.0, the answer also evolved. I came across this translating Objective-C code to Swift. I hope this helps someone! :-) Here is what it is today:

 context.setStrokeColor(UIColor.lightGray.cgColor) 

And this is ridiculous, this โ€œlight grayโ€ answer actually helps me debug the code too! Thank iou!

+2
Sep 09 '16 at 22:41
source share



All Articles