当在本机中输入超过 6 个字符时,如何更改 textInput 文本中的字体大小?

1 font-size textinput react-native

我想仅在 charLength 大于 6 时更改我们在 textInput 中输入的文本的字体大小。

实际字体大小为 80px,更改时应为 40 或小于等于

提前致谢

ben*_*nel 5

您可以为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} ]}
    />
  )
}
Run Code Online (Sandbox Code Playgroud)