react-native文字组件Text

本文介绍了React-Native的文字组件Text,包括行数控制、阴影设置、交互(单击和长按)以及文字装饰等功能,并提供了代码示例和学习交流资源。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

学习交流: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, backgroundColor:'#E6E6FA', color:"brown"}} numberOfLines={3}>
                    该组件为React中的一个基本组件,和Android的TextView组件类似,用来显示基本的文本信息,除了基本的显示布局之外,也可以进行嵌套布局
                    ,设置样式,以及做事件处理.
                </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, height: 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',
// 'solid', 'double', 'dotted', 'dashed'
textDecorationStyle: 'dashed', 
textDecorationColor: 'black',



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

番薯大佬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值