ReactNative实现文本渐变

我们直接上图,可以看到上面文本的效果,使用SVG实现

1.首先还是要引入react-native-svg库

2.使用该库下面的LinearGradient和Text

好,话不多说,我们看具体代码

复制代码
      <Svg width={422} height={30} viewBox={'0 0 422 30'}>
          <Defs>
            <LinearGradient
              id="Gradient"
              gradientUnits="userSpaceOnUse"
              x1="0"
              y1="0"
              x2={constNumberStyle[422]}
              y2="0">
              <Stop offset="0" stopColor={'rgba(49,122,247,1)'} />
              <Stop offset="1" stopColor={'rgba(255,123,76,1)'} />
            </LinearGradient>
            <Text
              id="Text"
              x={211}
              y={24}
              dominant-baseline="middle"
              fontSize={28}
              textAnchor="middle">
              文字是渐变色
            </Text>
          </Defs>
          <Use href="#Text" fill="url(#Gradient)" />
        </Svg>
相关推荐
lexiangqicheng4 小时前
rn入口文件setup.js解读
react native
sure2821 天前
react native 编写一个歌词组件
前端·react native
风景_fengjing2 天前
React Native + Expo搭建APP项目+安卓模拟器
react native·expo
pe7er4 天前
Reactnative 项目开发(最佳?)实践
react native
每天开心4 天前
从零开始:使用 Expo 构建你的第一个 React Native 应用
react native
冯志浩4 天前
React Native 状态管理 - useState
react native·掘金·金石计划
wayne2144 天前
ReactNative0.81版本发布
react native
木西5 天前
React Native DApp 开发全栈实战·从 0 到 1 系列(expo-router)
react native·web3·app
pe7er6 天前
React Native 多环境配置全攻略:环境变量、iOS Scheme 和 Android Build Variant
前端·react native·react.js
麦客奥德彪10 天前
解决 React Native iOS 与 OpenHarmony 开发环境冲突问题
react native·ios·harmonyos