[英]Converting UIColor to CGColor in swift
This is the Obj-C code:这是 Obj-C 代码:
CGContextSetStrokeColorWithColor(context, [[UIColor lightGrayColor] CGColor]);
How do I write it in swift.我如何快速编写它。
// Original answer.
var newColor = UIColor.lightGrayColor().CGColor
// Swift 3 version
var newColor = UIColor.lightGray.cgColor
Oddly enough, as Swift has evolved to 3.0 the answer has evolved as well.奇怪的是,随着 Swift 已经发展到 3.0,答案也随之发展。 I ran across this while converting some Objective C code to Swift.
我在将一些 Objective C 代码转换为 Swift 时遇到了这个问题。 I hope this helps someone!
我希望这可以帮助别人! :-) Here is what it is today:
:-) 这就是今天的情况:
context.setStrokeColor(UIColor.lightGray.cgColor)
And it's funny, this "light gray" answer is actually helping me debug some code too!有趣的是,这个“浅灰色”的答案实际上也在帮助我调试一些代码! Thank iou!
谢谢你!
斯威夫特 4+ 版本
UIColor.lightGray.cgColor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.