小编Pau*_*oco的帖子

React Native:完美对齐圆圈中的文本

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

vertical-alignment react-native

5
推荐指数
2
解决办法
6919
查看次数

标签 统计

react-native ×1

vertical-alignment ×1