Search code examples
iosswiftcore-graphics

Using a CGColor


According to the apple documentation for CGColor:

https://developer.apple.com/documentation/coregraphics/cgcolor/1455631-init

I should be able to create a CGColor with

CGColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5)

However, when I try to do this in XCode:

enter image description here

I am simply trying to create a function such that I can pass in a CGColor, and the CGColor parameter has a default value.

How do I go about doing this?


Solution

  • Because of that you read

    CGColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5)

    is only in Mac OS. iOS doesn't support it

    If you want to do the same in iOS, you can convert it from the UIColor by

    UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5).cgColor