我borderRadius在 React Native 中有一个圆形按钮(用 制作)。组件中的文本应垂直和水平居中。
Horyzontally 很好,但无论我做什么,垂直对齐似乎都失败了。即使它在小字体的大圆圈上看起来不错,小圆圈也证明它是错误的!
<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>
Run Code Online (Sandbox Code Playgroud)
虽然已经在别处回答,但我无法将文本(在这种情况下)正确地居中。
正如您在带有<Text>-Component绿色背景的图像上看到的那样,文本只是没有完美居中。即使它本身是完全对齐的......
这是世博会的小吃,整个代码减少到必要和不同的示例大小:https : //repl.it/@PaulHuchner/Centered-Text-in-Circles