How do I make text bold, italic, or underline in React Native?

前端 未结 4 806
囚心锁ツ
囚心锁ツ 2021-02-01 00:44

Surprisingly there isn\'t one question that groups these all together yet on Stack Overflow; there hasn\'t been an answer on SO for italics or underline, in fact, only this ques

相关标签:
4条回答
  • 2021-02-01 00:48
    <Text style={styles.bold}>I'm bold!</Text>
    <Text style={styles.italic}>I'm italic!</Text>
    <Text style={styles.underline}>I'm underlined!</Text>
    
    const styles = StyleSheet.create({
        bold: {fontWeight: 'bold'},
        italic: {fontStyle: 'italic'},
        underline: {textDecorationLine: 'underline'}
    })
    

    Working demo on Snack: https://snack.expo.io/BJT2ss_y7

    0 讨论(0)
  • 2021-02-01 00:55

    Only one line solution

    <Text style={{fontStyle: 'italic', fontWeight: 'bold', textDecorationLine: 'underline'}}>Bold, Italic & Underline Text</Text>
    
    0 讨论(0)
  • 2021-02-01 01:03
    <View style={styles.MainContainer}>
        <Text style={styles.TextStyle}>Example of Underline Text</Text>
    </View>
    
    TextStyle: {
        textAlign: 'center',
        fontWeight: 'bold'
        fontStyle: 'italic'
        fontSize: 20,
        textDecorationLine: 'underline',
        //line-through is the trick
    },
    
    0 讨论(0)
  • 2021-02-01 01:04

    You can see all possible att in this page https://reactnative.dev/docs/text

    for example ...

    textDecorationLine: enum('none', 'underline', 'line-through', 'underline line-through')
    
    0 讨论(0)
提交回复
热议问题