【发布时间】:2018-10-09 05:59:43
【问题描述】:
我在 React Native 中有一个圆形按钮(使用 borderRadius 制作)。组件中的文本应垂直和水平居中。
水平方向很好,但无论我做什么,垂直对齐似乎都失败了。即使它在具有小字体大小的大圆圈上看起来不错,但小圆圈证明它是错误的!
<View style = {{
alignItems:'center',
justifyContent:'center',
backgroundColor:'yellow',
borderColor: this.props.color,
width:size, height:size,
borderRadius:size,
borderWidth:borderWidth,
}}>
<Text style = {{
textAlign: 'center',
backgroundColor:'none',
fontSize:fontSize,
lineHeight:fontSize,
}}>
{this.props.title}
</Text>
</View>
虽然已经回答了elsewhere,但我无法将文本(在这种情况下)正确地居中。
正如您在<Text>-Component 的绿色背景图像上看到的那样,文本没有完全居中。即使它本身是完美对齐的......
这里是 Expo 的小吃,整个代码减少到必要的大小,并具有不同的示例大小:https://repl.it/@PaulHuchner/Centered-Text-in-Circles
【问题讨论】:
标签: react-native vertical-alignment