Android
1.最简单是使用xml实现渐变
<gradient
android:angle=“180”
android:endColor=“#ffffff”
android:startColor=“#000000” />
</shape>
2.使用LinearGradient
LinearGradient一般使用在自定义view上
int [] colors = {Color.BLACK,Color.RED, Color.GREEN};
float[] position = {0f, 0.3f, 1.0f};
LinearGradient linearGradient = new LinearGradient(0,0,width,0,colors,position, Shader.TileMode.CLAMP);
myPaint.setShader(linearGradient);
canvas.drawRect(0,0, width/2,myPaint);
Color可设置多个,position也是如此,类似转折点,这个理解起来比较简单
Ios
渐变比较麻烦,看看这位博主的实现方式:https://blog.csdn.net/weixin_30315905/article/details/96695016