objective-c 快速将 UIColor 转换为 CGColor
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27821785/
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
Converting UIColor to CGColor in swift
提问by Shakti Chauhan
This is the Obj-C code:
这是 Obj-C 代码:
CGContextSetStrokeColorWithColor(context, [[UIColor lightGrayColor] CGColor]);
How do I write it in swift.
我如何快速编写它。
回答by Onik IV
// Original answer.
var newColor = UIColor.lightGrayColor().CGColor
// Swift 3 version
var newColor = UIColor.lightGray.cgColor
回答by George D Girton
Oddly enough, as Swift has evolved to 3.0 the answer has evolved as well. I ran across this while converting some Objective C code to Swift. I hope this helps someone! :-) Here is what it is today:
奇怪的是,随着 Swift 已经发展到 3.0,答案也随之发展。我在将一些 Objective C 代码转换为 Swift 时遇到了这个问题。我希望这可以帮助别人!:-) 这就是今天的情况:
context.setStrokeColor(UIColor.lightGray.cgColor)
And it's funny, this "light gray" answer is actually helping me debug some code too! Thank iou!
有趣的是,这个“浅灰色”的答案实际上也在帮助我调试一些代码!谢谢你!

