React Native TextInput在iOS上呈现过高的文本,会切断某些字符的顶部
我的react原生应用程序中有一个简单的文本输入。以下是相关代码:React Native TextInput在iOS上呈现过高的文本,会切断某些字符的顶部,ios,react-native,textinput,Ios,React Native,Textinput,我的react原生应用程序中有一个简单的文本输入。以下是相关代码: <View style={styles.AmountWrapper}> <TextInput multiline={true} placeholder="$0" placeholderTextColor={colors.black38} style={styles.NumberInput} keyboardType={"nu
<View style={styles.AmountWrapper}>
<TextInput
multiline={true}
placeholder="$0"
placeholderTextColor={colors.black38}
style={styles.NumberInput}
keyboardType={"numeric"}
/>
</View>
let styles = StyleSheet.create({
AmountWrapper: {
flexDirection: "column",
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: colors.white
},
NumberInput: {
flexDirection: "row",
alignItems: "center",
flex: 0,
fontFamily: styleHelper.fontFamily("medium"),
fontSize: 48,
paddingHorizontal: 16,
paddingTop: 0,
paddingBottom: 0,
color: colors.blue,
textAlign: "center",
borderWidth: 0,
textAlignVertical: "center"
},
});
让styles=StyleSheet.create({
数量:{
flexDirection:“列”,
弹性:1,
对齐项目:“中心”,
辩护内容:“中心”,
背景颜色:colors.white
},
数字输入:{
flexDirection:“行”,
对齐项目:“中心”,
弹性:0,
fontFamily:styleHelper.fontFamily(“中”),
尺寸:48,
水平方向:16,
paddingTop:0,
填充底部:0,
颜色:颜色,蓝色,
textAlign:“居中”,
边框宽度:0,
text垂直对齐:“中心”
},
});
我在Android Studio Pixel 3上模拟Android 9.0,在Xcode的模拟器上模拟iOS 12.4 iPhone X
在Android上,这正是我想要的:
问题在于iOS。它将文本渲染得太高,切断了美元符号的顶部和数字的几个像素。它通过占位符和用户输入文本来实现:
我尝试过更改边距、填充、textAlign、线宽、flexDirection、alignItems和justifyContent。我还尝试在TextInput中使用multiline={false}
如何让iOS进一步渲染文本,并在TextInput中正确显示?我认为,在iOS上,高度和线条高度的正常行为会被某些内容覆盖。在IOS上的react native works for me中设置lineHeight或设置textInput的高度。我建议将其中一个设置为至少和fontSize一样大的尺寸,然后在样式中注释出线条,以确定是哪一个通过消除过程导致了它。下面是一个在我的一个项目中有效的样式示例:
<TextInput style={styles.inputsTwo}
accessible={this.state.access}
placeholder="Email"
clearButtonMode="always"
onChangeText={text => this.setState({email: text})}
value={this.state.email}
/>
<TextInput style={styles.inputs}
accessible={this.state.access}
placeholder="Password"
secureTextEntry={true}
clearButtonMode="always"
onChangeText={text => this.setState({password: text})}
value={this.state.password}
/>
在用尽所有其他选项后,字体文件本身似乎存在问题。不确定问题到底是什么,但其他字体不会造成此问题。Android没有问题,但iOS有问题。
inputs: {
textDecorationLine: 'underline',
marginBottom: 5,
textAlign: 'left',
marginLeft: 30,
marginRight: 30,
borderBottomColor: '#808080',
borderBottomWidth: 2,
height: 48,
fontSize: 48
},
inputsTwo: {
textDecorationLine: 'underline',
marginBottom: 10,
textAlign: 'left',
marginLeft: 30,
marginRight: 30,
borderBottomColor: '#808080',
borderBottomWidth: 2,
height: 48,
fontSize: 48
},