微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐