我想仅在 charLength 大于 6 时更改我们在 textInput 中输入的文本的字体大小。
实际字体大小为 80px,更改时应为 40 或小于等于
提前致谢
最佳答案
您可以为 TextInput
提供条件样式成分。
示例
_onChangeText(text) {
this.setState({ fontSize: text.length > 6 ? 40 : 80 });
}
render() {
return (
// Giving an array of objects to style property can help you to define a -- default value
<TextInput
onChangeText={this._onChangeText.bind(this)}
style={[ {fontSize: 80}, {fontSize: this.state.fontSize} ]}
/>
)
}
关于react-native - 当在 native 中输入超过 6 个字符时,如何更改 textInput 文本中的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46427133/