javascript 如何在 react-native 中更改占位符 textSize

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33515911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:34:55  来源:igfitidea点击:

how to change placeholder textSize in react-native

javascriptreact-native

提问by Hussian Shaik

hai in my TextInput i want to change the size of the font of placeHolder,i tried like this:

在我的 TextInput 中,我想更改 placeHolder 的字体大小,我试过这样的:

<TextInput
                   style={styles.email}
                   value={this.state.email} 
                   placeholder="Email"
                 placeholderTextColor="red"
                 //placeholderTextSize = 20px
                   onChange={this.handleEmailChange.bind(this)}
                   onBlur={this.onBlur.bind(this)}/>

when i wrote like this color is working for me but size is not working,can any one give me suggestions how to change the size of placeholder Text,any help much appreciated

当我写这样的颜色对我有用但大小不起作用时,任何人都可以给我建议如何更改占位符文本的大小,非常感谢任何帮助

回答by BigPun86

I am not sure if you can specify only the size of placeholderText. But you can change the fontSize of the input text from your TextInput:

我不确定您是否只能指定 placeholderText 的大小。但是您可以从 TextInput 更改输入文本的 fontSize:

var styles = StyleSheet.create({
 email:     {
    fontSize:   12, <-- Textsize of Input-Text and Placeholder-Text
 },
})

Maybe your solution works without px?! But i don′t think so. If you want to have a different PlaceholderText than the InputText, than you could maybe acces the onChangeText-Method of TextInput and change the fontSize as soon as you type something into the Textfield.

也许您的解决方案在没有 px 的情况下有效?!但我不这么认为。如果您想要一个与 InputText 不同的 PlaceholderText,那么您可以访问 TextInput 的 onChangeText-Method 并在您在 Textfield 中输入内容后立即更改 fontSize。

回答by Mian Jawad Ahmad

<TextInput 
style={{fontSize:12}} 
placeholder='any text' 
onChangeText={(input)=>this.setState({input: input})}
placeholderTextColor='green'/>