【问题标题】:React Native - Show the first line of text in BoldReact Native - 以粗体显示第一行文本
【发布时间】:2019-08-07 11:02:35
【问题描述】:

在我的应用程序中,我有笔记,我想以粗体显示我的文本的第一行,如下图所示

以上截图来自小米笔记应用

【问题讨论】:

    标签: react-native


    【解决方案1】:

    我建议你把你的音符串一分为二,然后很容易分开,这是一个非常简单的例子:

    import React, { Component } from 'react';
    import { Text, StyleSheet } from 'react-native';
    
    export default class TextComponent extends Component {
      constructor(props) {
        super(props);
        this.state = {
          titleText: "Hi there,",
          bodyText: 'Redmi 3S/Prime will receive the MIUI 9 stable UPdate in mid-late December. Stay...'
        };
      }
    
      render() {
        return (
          <Text style={styles.baseText}>
            <Text style={styles.titleText}>
              {this.state.titleText}{'\n'}
            </Text>
            <Text numberOfLines={5}>
              {this.state.bodyText}
            </Text>
          </Text>
        );
      }
    }
    
    const styles = StyleSheet.create({
      baseText: {
        fontFamily: 'Cochin',
      },
      titleText: {
        fontWeight: 'bold',
      },
    });
    
    

    【讨论】:

      猜你喜欢
      • 2013-02-10
      • 2017-11-20
      • 1970-01-01
      • 2018-07-03
      • 2013-07-01
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      相关资源
      最近更新 更多