react native Text实现限制行数不显示省略号,尾部直接截断
来源:互联网 发布:北京软件开发平均工资 编辑:程序博客网 时间:2024/06/05 20:43
react native Text实现限制行数,尾部直接截断。直接在下一行加省略号。
效果如图:
//超过三行就在底部加上省略号
用传统的方法只能实现在尾部加省略号,不过现在新版的RN,ellipsizeMode 属性配上
numberOfLines属性 也能实现这样的效果。不过对于老版的RN就无能为力了。刚好用的老版RN又要实现这样的效果就查资料然后想了想,然后就实现了一个这样的效果,废话不多说,上干货。
import React, { Component } from 'react';
import {
View,
Text,
Dimensions,
TouchableOpacity,
StyleSheet,
} from 'react-native';
const devicesWidth=Dimensions.get('window').width;
class MyText extends Component {
constructor(props) {
super(props);
this.state={
height:0,
tag:0,
};
}
textOnLayout(e){
const layout = e.nativeEvent.layout;
if(layout.height>60){ //行高是20然后把text的高度设置为60就能保证行数控制在3行了
this.refs.text.setNativeProps({
style:{
height:60,
width:devicesWidth-74,
}
});
this.setState({
tag:1,
});
}
}
render() {
return(
<View >
<Text
ref="text"
style={styles.text}
onLayout={this.textOnLayout.bind(this)}
>
{this.props.text}
</Text>
{this.state.tag===0?(<View></View>):(<Text style={styles.text1}>......</Text>)}
</View>
);}
}
const styles = StyleSheet.create({
text: {
fontSize:15,
lineHeight:20,
color: '#323232',
width:devicesWidth-74,
},
text1: {
fontSize:15,
lineHeight:20,
color: '#323232',
},
});
module.exports=MyText;
- react native Text实现限制行数不显示省略号,尾部直接截断
- React Native实现Text显示...的效果
- android文本限制输入行数,多余部分显示省略号
- Android中TextView限制行数及末尾已省略号显示
- android EditText文本限制输入行数,多余部分显示省略号
- React Native 指定文字行数,超出行数显示更多
- React Native之Text嵌套显示
- 安卓笔记:限制行数显示,限制字数显示,多余部分省略号表示
- react native实现可展开Text控件
- react native实现可展开Text控件
- react-native 图片不显示问题
- android textView多出来的text不显示省略号
- React Native Text技巧
- React-Native中的Text
- TextView限制最大行数,多出部分显示省略号,解决ellipsize = "end" 失效的问题
- 使用 text-overflow: ellipsis 实现溢出文本省略号显示
- CSS用text-overflow实现文本标题超出显示省略号“...”
- Js 实现字数限制,超出部分显示为省略号
- 悲观锁
- 使用ffmpeg合并视频文件的三种方法
- hive查询与优化
- 2017/8/9 离线赛
- 机器学习算法总结--随机森林
- react native Text实现限制行数不显示省略号,尾部直接截断
- JAVA常用日期比较操作说明
- 说一说排序算法,稳定性,复杂度
- vue
- 数字签名与数字证书技术简介(一)
- Scala 之 模式匹配
- 常用Markdown(MD)语法
- 正则表达式--初级
- 乐观锁