【问题标题】:text shadow in react native反应本机中的文本阴影
【发布时间】:2018-03-05 08:51:58
【问题描述】:

在我的网站中,我有一个带有此文本阴影的标题:

h1.title {
 text-shadow: -1px 1px 10px rgba(0, 0, 0, 0.75)
 }
<h1 class="title">title</h1>

我想在我的 react native 应用中做同样的事情。

我看过属性:

textShadowColor color
textShadowOffset {width: number, height: number}
textShadowRadius number

但是我不知道怎么实现和html一样的效果。

我该怎么办?

【问题讨论】:

  • 您可以通过以下格式为<Text></Text>添加阴影textShadowColor: '#000', textShadowOffset: { width: 0.5, height: 0.5 }, textShadowRadius: 1,

标签: react-native shadow


【解决方案1】:

我在我的 react native 应用中尝试这样

<Text 
    style={{
        color: "white", 
        textShadowColor: 'black', 
        textShadowOffset: { width: -1, height: 0 },
        textShadowRadius: 10, 
        fontSize: hp('2%'), 
        fontWeight: '800'}}
    >
    Online Sports Store to Buy Sports Goods,
</Text>

【讨论】:

    【解决方案2】:

    我尝试了 bennygenel 爵士的回答,它奏效了。 我用过这样的东西...

    <View>
        <Text style={styles.textWithShadow}>Hello world</Text>
    </View>
    

    .....

    const styles = StyleSheet.create({
         textWithShadow:{
             textShadowColor: 'rgba(0, 0, 0, 0.75)',
             textShadowOffset: {width: -1, height: 1},
             textShadowRadius: 10
         }
    });
    

    【讨论】:

    • 这真的有用吗?您基本上已经复制并粘贴了先前的答案。也许您应该将您的修订发布为对上述答案的评论。
    • 谢谢。我也试过了,但我不能写评论。它说我必须至少有 50 个声望。这不会再发生了,抱歉。
    【解决方案3】:

    CSS text-shadow 具有以下语法,

    文本阴影:h-shadow v-shadow 模糊半径颜色|none|initial|inherit;

    要实现与您提供的 css 类似的效果,您可以使用类似这样的东西,

    // text-shadow: -1px 1px 10px rgba(0, 0, 0, 0.75)
    
    {
      textShadowColor: 'rgba(0, 0, 0, 0.75)',
      textShadowOffset: {width: -1, height: 1},
      textShadowRadius: 10
    }
    

    【讨论】:

    • 对仍然无法显示文本阴影的任何人的说明 - 似乎与 CSS 不同,半径值不能为 0,请尝试 textShadowRadius: 1 至少在 Android 中这似乎是正确的,我没试过ios。
    • 有没有人想出如何阻止阴影的边缘被文本框的边缘切断?我尝试了溢出:在它和它的所有父母身上都可见,但没有运气。
    • @JamesTrickey,尝试添加一些填充
    猜你喜欢
    • 2021-10-22
    • 1970-01-01
    • 2019-06-24
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多