Color Locations

Another property is locations. It is an array of floating-point values (boxed as NSNumber objects) defining the location of each stop.

The gradient stops are specified as values between 0 and 1. The values must be monotonically increasing. You must ensure that the number of locations matches the number of colors or you’ll get a blank gradient. If nil, the stops are spread uniformly across the range. Defaults to nil.

This property is animatable, that means you can change the colors locations in an animated way.

A three-color gradient, using the locations array

And what about programming code?

What happens if we set the [0.6, 0.3, 0.2] values as the locations for the colors?

A three-color gradient with incorrect locations

Please, don’t forget that the values must be monotonically increasing or you’ll get a wrong gradient.



Source link https://blog..io/become-a-gradient--with--c0fd87f7fe67?source=rss—-eb297ea1161a—4

LEAVE A REPLY

Please enter your comment!
Please enter your name here