安装 link

yarn add  react-native-linear-gradient

react-native link   react-native-linear-gradient

link 之后就可以使用了

 

import LinearGradient from 'react-native-linear-gradient';

 

 

<LinearGradient colors={['#237af4', '#56b2e3', '#237af4']} style={{flex:1}}></LinearGradient>

默认 是从上往下渐变的:如图

react-native 渐变组件 react-native-linear-gradient

 

如果想从左到右,或者倾斜渐变 就需要加属性了

start:{ x: number, y: number }
end:{ x: number, y: number }

start 就是渐变开始的位置,x、y 范围是 0 - 1 ,
end 同上,就是渐变结束的位置

 

<LinearGradient
            start={{x:1,y:0}}
            end={{x:0,y:1}}
            colors={['#237af4', '#56b2e3', '#237af4']} style={{flex:1}}></LinearGradient>

react-native 渐变组件 react-native-linear-gradient

 

 详细的可以看下面这2个地址

官方文档地址   https://www.jianshu.com/p/757dfeae5162

 

相关文章:

  • 2021-06-20
  • 2021-10-16
  • 2022-12-23
  • 2021-11-27
  • 2021-04-21
  • 2021-10-01
  • 2021-07-22
  • 2021-06-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-02
  • 2021-11-10
相关资源
相似解决方案