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>
相关推荐
前端小D16 天前
React Native项目开发(iOS侧为例)
javascript·react native·react.js
大龄秃头程序员16 天前
从源码里看懂 React Native 新架构:TurboModule 与 Fabric 到底是怎么跑起来的?
react native
前端小D18 天前
React Native Android 项目搭建
android·react native·react.js
hhhjhl20 天前
React Native 三方库「react-native-sha256」的鸿蒙化适配指南
react native·华为·harmonyos
2601_9499706920 天前
React Native 三方库「react-native-version-check」的鸿蒙化适配指南
react native·华为·harmonyos
hhhjhl20 天前
React Native 三方库「react-native-proximity」的鸿蒙化适配指南
react native·华为·harmonyos
2601_9499706920 天前
React Native 三方库「react-native-media-notification」的鸿蒙化适配指南
react native·华为·harmonyos
GitCode官方20 天前
从大语言模型到具身智能:百度百舸 LoongForge 入驻 AtomGit
人工智能·react native·百度·harmonyos·atomgit
2501_9159184123 天前
Windows 上开发 React Native iOS,真机调试、Fast Refresh 与打包 ipa
windows·vscode·react native·ios·个人开发·swift·敏捷流程
2501_9481226324 天前
Qs 跨端三方库仓颉适配全流程
python·react native·django·tornado