我如何使文本粗体,斜体,或在反应本机下划线?

令人惊讶的是,在 Stack Overflow 上没有一个问题将这些内容组合在一起; 在 SO 上没有斜体或下划线的答案,实际上,只有粗体的 这个问题。我在下面自我回答了这个问题。

206982 次浏览
<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'}
})

零食工作演示: https://snack.expo.io/BJT2ss_y7

<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
},

只有一条线

<Text style=\{\{fontStyle: 'italic', fontWeight: 'bold', textDecorationLine: 'underline'}}>Bold, Italic & Underline Text</Text>

您可以在此页面中看到所有可能的 att Https://reactnative.dev/docs/text

比如说。

textDecorationLine: enum('none', 'underline', 'line-through', 'underline line-through')

只供使用

<Text style={styles.textStyle}>I'm Underline!</Text>


const styles = StyleSheet.create({
textStyle: {
textDecorationLine: 'underline'
}
})

其他装饰有:

  1. 没有
  2. 下划线
  3. 直线通过
  4. 划线穿过