Drawing an angle/angular/“Conical”/“Arcing” gradient in Objective-C (IOS) using Core Graphics

后端 未结 3 595
轮回少年
轮回少年 2020-12-19 17:31

I\'m trying to draw a \"conical\"/\"arcing\" gradient (I don\'t know what would be the correct term for this) (Photoshop calls it an \"angle\" gradient —your friendly ne

3条回答
  •  甜味超标
    2020-12-19 17:51

    The thread linked above suggests using pre-made images, but this isn't an option because the colors of the gradient should be settable, the view should be resizable and the fill of the progress bar isn't always 100% full obviously (which would be the state of the gradient as shown in the picture in the thread above).

    Not a problem!

    Use the very black-to-white image from the other question (or a bigger version if you need one), in the following fashion:

    1. Clip to whatever shape you want to draw the gradient in.
    2. Fill with the color at the end of the gradient.
    3. Use the black-to-white gradient image as a mask.
    4. Fill with the color at the start of the gradient.

    You can rotate the gradient by rotating the mask image.

    This only supports the simplest case of a gradient with a color at each extreme end; it doesn't scale to three or more colors and doesn't support unusual gradient stop positioning.

提交回复
热议问题