Converting UIColor to CGColor in swift

前端 未结 3 567
旧巷少年郎
旧巷少年郎 2020-12-23 15:39

This is the Obj-C code:

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

How do I write it in swift.

相关标签:
3条回答
  • 2020-12-23 16:16
    // Original answer.
    var newColor = UIColor.lightGrayColor().CGColor
    
    // Swift 3 version
    var newColor = UIColor.lightGray.cgColor
    
    0 讨论(0)
  • 2020-12-23 16:17

    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:

    context.setStrokeColor(UIColor.lightGray.cgColor)
    

    And it's funny, this "light gray" answer is actually helping me debug some code too! Thank iou!

    0 讨论(0)
  • 2020-12-23 16:17

    Swift 4+ version

    UIColor.lightGray.cgColor
    
    0 讨论(0)
提交回复
热议问题