I am using “DrawLinearGradient” function to draw gradient line. But the 2 colors that i am using are not dividing equally in the line

前端 未结 1 1153
你的背包
你的背包 2021-01-25 23:47

I am using \"DrawLinearGradient\" function to draw gradient line. But the 2 colors that i am using are not dividing equally in the line.

CGColorSpace colorSpace          


        
相关标签:
1条回答
  • 2021-01-26 00:29

    I'm assuming that the Mono implementation has the same requirements as the original C implementation.

    From the documentation of CGGradientCreateWithColors(colorSpace, colors, locations[]) (that should correspond to new CGGradient(colorSpace,colors,locations); in Mono) you can read

    The locations array should contain the same number of items as the colors array.

    In your code however you are passing two colors but four locations.

    Since you are saying "dividing equally in the line" you should probably repeat both colors twice.

    CGColor[] colors = {UIColor.Red.CGColor, UIColor.Red.CGColor, UIColor.Green.CGColor ,UIColor.Green.CGColor};
    float[] locations = {0.0f,0.5f,0.5f,1.0f};
    
    0 讨论(0)
提交回复
热议问题