首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在react-native-svg元素中实现属性填充

如何在react-native-svg元素中实现属性填充
EN

Stack Overflow用户
提问于 2020-01-06 13:37:40
回答 1查看 718关注 0票数 2

我有一个用路径/线绘制的简单三角形,从AdobeXD导出为SVG,然后将SVG代码复制并调整到带有react-native-svg库元素的react-native项目中。我试图填充元素的背景,因为我不希望它是透明的。我以为它会像在G元素中使用web的fill属性一样简单,但它不起作用。

下面是SVG代码:

代码语言:javascript
复制
<Svg width="22.364" height="20.315" viewBox="0 0 22.364 20.315">
    <G fill="#fff" transform="translate(0.682 0.632)">
        <Line
            id="Line_37"
            data-name="Line 37"
            x1="21"
            y1="12"
            transform="translate(0 7)"
            stroke="rgba(69,74,102, .5)"
            stroke-linecap="round"
            stroke-width="1"
        />
        <Line
            id="Line_38"
            data-name="Line 38"
            y2="19"
            transform="translate(21)"
            stroke="rgba(69,74,102, .5)"
            stroke-linecap="round"
            stroke-width="1"
        />
        <Line
            id="Line_40"
            data-name="Line 40"
            x1="21"
            y2="7"
            stroke="#fff"
            stroke-linecap="round"
            stroke-width="1"
        />
    </G>
</Svg>

查看了react-native-svg的文档,他们说“填充属性指的是形状内部的颜色”。但就像我说的,fill属性在<Svg>元素和<G>元素中都不起作用……你有什么想法?

EN

回答 1

Stack Overflow用户

发布于 2020-05-29 00:25:54

G上设置fill属性会对子元素(在本例中是Line元素)产生影响,而不是对整个组产生影响。

您可以绘制一个覆盖整个SVG的白色矩形,以完成您想要的功能:

代码语言:javascript
复制
<Svg width="22.364" height="20.315" viewBox="0 0 22.364 20.315">
<Rect
    x="0"
    y="0"
    width="100%"
    height="100%"
    fill="white"
/>
<G fill="#fff" transform="translate(0.682 0.632)">
    <Line
        id="Line_37"
        data-name="Line 37"
        x1="21"
        y1="12"
        transform="translate(0 7)"
        stroke="rgba(69,74,102, .5)"
        stroke-linecap="round"
        stroke-width="1"
    />
    <Line
        id="Line_38"
        data-name="Line 38"
        y2="19"
        transform="translate(21)"
        stroke="rgba(69,74,102, .5)"
        stroke-linecap="round"
        stroke-width="1"
    />
    <Line
        id="Line_40"
        data-name="Line 40"
        x1="21"
        y2="7"
        stroke="#fff"
        stroke-linecap="round"
        stroke-width="1"
    />
</G>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59607150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档