有没有办法设置fontStyle:’italic’仅为React Native中的TextInput的占位符?
看起来像here at the documentation似乎只能设置一个占位符和placeholderTextColor.
解决方法
改进丹尼尔的一个更通用的解决方案的答案
class TextInput2 extends Component { constructor(props) { super(props); this.state = { placeholder: props.text.length == 0 } this.handleChange = this.handleChange.bind(this); } handleChange(ev) { this.setState({ placeholder: ev.nativeEvent.text.length == 0 }); this.props.onChange && this.props.onChange(ev); } render() { const { placeholderStyle,style,onChange,...rest } = this.props; return <TextInput {...rest} onChange={this.handleChange} style={this.state.placeholder ? [style,placeholderStyle] : style} /> } }
用法:
<TextInput2 text={this.state.myText} style={{ fontFamily: "MyFont" }} placeholderStyle={{ fontFamily: "AnotherFont",borderColor: 'red' }} />