Hi,
I need an NSArray
containing CGColorRef
s for CAGradientLayer
. I create it like this. The INSTANCE
fields are of type UIColor
:
NSArray.arrayWithObjects<CGColorRef>(IosRed.INSTANCE.CGColor(), IosShadowBlack.INSTANCE.CGColor(), null)
The strange thing is that the first color is not picked up by the gradient. The layer uses a fully transparent color instead of the first color.
When I inspect the contents of the array with the following code:
val first = SHADOW_GRADIENT_COLORS.get(0)
println("First: ${if (first is CGColorRef) CoreGraphics.CGColorGetAlpha(first) else "Not a color: ${first?.javaClass?.simpleName}"}")
val second = SHADOW_GRADIENT_COLORS.get(1)
println("Second: ${if (second is CGColorRef) CoreGraphics.CGColorGetAlpha(second) else "Not a color: ${second?.javaClass?.simpleName}"}")
I get the following output:
First: 1.0
Second: Not a color: NSObject
So the first object is actually a CGColorRef
, but CAGradientLayer
cannot use it and defaults to a fully transparent color. The second object is not a CGColorRef
, but CAGradientLayer
does use the color that I want for it.
What am I doing wrong? How do I create the array correctly so the first color is correctly picked up?
Regards, Johan