react-native文字组件Text

学习交流:https://gitee.com/potato512/Learn_ReactNative

react-native学习交流QQ群:806870562


效果


代码示例

import React,{ Component } from 'react';
import {
    StyleSheet,View,Text,Alert
} from 'react-native';

type Props = {};
export default class TextPage extends Component<Props> {
    render() {
        return(
            <View style={styles.containerStyle}>
                <Text style={styles.textStyle}>文字组件</Text>
                <Text style={{margin:10,fontWeight:"normal",fontSize:20,color:"green",textAlign:'right',writingDirection:'rtl'}}>
                    左对齐且从右向左排列显示。
                </Text>
                <Text style={{margin:10,backgroundColor:'#E6E6FA',color:"brown"}}>
                    该组件为React中的一个基本组件,和Android的TextView组件类似,用来显示基本的文本信息,除了基本的显示布局之外,也可以进行嵌套布局,设置样式,以及做事件处理.
                </Text>
                <Text style={{margin:10,color:"brown"}} numberOfLines={3}>
                    该组件为React中的一个基本组件,以及做事件处理.
                </Text>
                <Text style={{height:30,margin:10}} onPress={() => {
                    Alert.alert("单击了文字组件");
                }}>文字单击</Text>
                <Text style={{height:30,margin:10}} onLongPress={() => {
                    Alert.alert("长按了文字组件")
                }}>文字长按</Text>
            </View>

        );
    }
}

var styles = StyleSheet.create({
    containerStyle: {
        margin:20,backgroundColor:'#FFFACD',},textStyle: {
        height:50,backgroundColor:"#DCDCDC",color:"#F08080",fontSize: 30,fontStyle:'normal',fontWeight:'bold',textdecorationLine: 'underline',textdecorationStyle: 'dashed',// 'solid','double','dotted','dashed'
        textdecorationColor: 'black',letterSpacing:10,lineHeight:50,writingDirection:'auto',// auto,ltr,rtl
        textAlign:'center',// 文字阴影偏移
        textShadowOffset: {width: 10,height: 10},// 文字阴影颜色
        textShadowColor: 'black',// 文字阴影圆角的大小
        textShadowRadius: 5,}
});

文字组件特性

1、行数控制

<Text numberOfLines={3}></Text>

2、阴影设置

// 文字阴影偏移
textShadowOffset: {width: 10,// 文字阴影颜色
textShadowColor: 'black',// 文字阴影圆角的大小
textShadowRadius: 5,

3、交互

(1)单击

<Text onPress={() => {
	Alert.alert("单击了文字组件");
}}>文字单击</Text>

(2)长按

<Text onLongPress={() => {
	Alert.alert("长按了文字组件")
}}>文字长按</Text>

4、文字装饰

// 'none','underline','line-through','underline line-through'
textdecorationLine: 'underline','dashed'
textdecorationStyle: 'dashed',textdecorationColor: 'black',

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...