gpt4 book ai didi

javascript - React-Native 省略最后一个字符

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:11:45 24 4
gpt4 key购买 nike

每当我在一个元素中放置一个超过 5 个字符的字符串时,最后一个字符不会被渲染。这是我的代码和输出的字符串。

const Header = () => {
const { textStyles, viewStyles } = styles;

return (
<View style={viewStyles}>
<Text style={textStyles}>Albums</Text>
</View>
);
};

const styles = {
viewStyles: {
backgroundColor: '#F8F8F8',
alignItems: 'center',
justifyContent: 'center',
height: 60,
paddingTop: 15,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
elevation: 2
},
textStyles: {
fontSize: 20
},
};

输出字符串:专辑

如果我将 Text 元素内的字符串更改为类似 'Albums!' 的字符串,输出将是 Albums。它总是显示 n-1 个字符。

最佳答案

我测试了你的代码伙伴它工作正常

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

const Header = () => {
const { textStyles, viewStyles } = styles;

return (
<View style={viewStyles}>
<Text style={textStyles}>Albums!!!!</Text>
</View>
);
};
export default class App extends React.Component {

render() {
return (
<View>
<Header></Header>
</View>
);
}
}

const styles = StyleSheet.create({
viewStyles: {
backgroundColor: '#F8F8F8',
alignItems: 'center',
justifyContent: 'center',
height: 60,
paddingTop: 15,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
elevation: 2
},
textStyles: {
fontSize: 20
},
});

这是输出

enter image description here

关于javascript - React-Native <Text> 省略最后一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48429495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com