How to create text border in React Native?

前端 未结 9 1550
清歌不尽
清歌不尽 2021-02-01 14:14

In React-Native, how do I add font borders to Text-components?

I\'ve tried using border and shadow{Color, Radius, Opacity, Offset}, but haven\'

相关标签:
9条回答
  • 2021-02-01 14:40

    Is currently not working for android. Try wrap it within a <View style={{borderWidth: 1}}/>

    0 讨论(0)
  • 2021-02-01 14:40

    As noted by KChen, you need to add both borderColor and borderWidth. Just updating this answer for later versions of ReactNative (note the usage of 'styles.bigblue').

    import React, { Component } from 'react';
    import { AppRegistry, StyleSheet, ScrollView, Image, Text } from 'react-native';
    
    export default class HelloWorldWithBorder extends Component {
            render() {
                    return (
                                    <ScrollView>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                    </ScrollView>
                           );
            }
    }
    
    
    const styles = StyleSheet.create({
            bigblue: {
                    color: 'blue',
                    fontWeight: 'bold',
                    fontSize: 20,
                    borderColor: 'black',
                    borderWidth: 1
            }
    });
    

    This was using a combination of the tutorial from Styles and ScrollView

    0 讨论(0)
  • 2021-02-01 14:41

    you can emulator border as two attributes :

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

    Ex:

    textshadow:{
        fontSize:100,
        color:'#FFFFFF',
        fontFamily:'Times New Roman',
        paddingLeft:30,
        paddingRight:30,
        textShadowColor:'#585858',
        textShadowOffset:{width: 5, height: 5},
        textShadowRadius:10,
      },

    0 讨论(0)
提交回复
热议问题