ios - React Native TextInput 在 iOS 上渲染文本太高,切断某些字符的顶部
问题描述
我的反应本机应用程序中有一个简单的 TextInput。以下是相关代码:
<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"
},
});
我正在使用 Android 9.0 和 Xcode 的模拟器模拟 iOS 12.4 iPhone X 的 Android Studio Pixel 3。
在 Android 上,这正是我想要的呈现方式:
问题出在 iOS 上。它使文本太高了,切断了美元符号的顶部,以及数字的几个像素。它使用占位符以及当用户输入文本时执行此操作:
我尝试过更改边距、填充、textAlign、lineHeight、flexDirection、alignItems 和 justifyContent。我也在multiline={false}
TextInput 中尝试过。
如何让 iOS 进一步向下渲染文本并在 TextInput 中正确显示?
解决方案
我认为您对 IOS 上的 height 和 lineHeight 有一些压倒一切的正常行为。在 IOS 上,在 react native 中设置 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}
/>
然后在我的风格中:
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
},
推荐阅读
- bash - 具有多序列比对的 Psiblast 失败
- python - Python 中 Beam 的 LeftOuterJoin
- windows - 如何在 Power BI 中模拟当前日期值?
- android - 使用 singleTask 时如何知道从动态快捷方式启动的 Activity?
- handlebars.js - 是否可以在 Palantir-Foundry 的 Slate 中定义另一个车把内的车把?
- python - 使用python将条形码解码数据(13位数字)插入带有网络摄像头的SQL Server
- git - 忽略 git status 中未跟踪的旧文件
- c - C中不兼容的指针类型的赋值
- c# - 在使用 String.Format("{0:n}", 1234) 时,我将输出保留到小数点后三位,而我需要带逗号的小数点后两位
- r - R在表达式中添加换行符