2017-04-12 124 views

回答

46

三个点你可以只使用一个底部边框空视图。

<View 
    style={{ 
    borderBottomColor: 'black', 
    borderBottomWidth: 1, 
    }} 
/> 
+0

我必须考虑这种方式。谢谢! – gumkins

+2

我推荐'borderBottomWidth:StyleSheet.hairlineWidth' :) –

+0

如果它不工作,请考虑添加alignSelf:'stretch'。 – Scientist1642

0

你为什么不这样做?

<View 
    style={{ 
    borderBottomWidth: 1, 
    borderBottomColor: 'black', 
    width: 400, 
    }} 
/> 
2
import { View, Dimensions } from 'react-native' 

var { width, height } = Dimensions.get('window') 

// Create Component 

<View style={{ 
    borderBottomColor: 'black', 
    borderBottomWidth: 0.5, 
    width: width - 20,}}> 
</View> 
5

人们可以为了利用保证金来改变的宽度线并将其置于中心。

<View style = {styles.lineStyle} /> 

lineStyle:{ 
     borderWidth: 0.5, 
     borderColor:'black', 
     margin:10, 
    } 

如果您想要动态给边距,那么您可以使用尺寸宽度。

+0

谢谢。你也可以只是''因为之间没有任何东西;-) –

+0

欢迎你。编辑! – Smit

2

我最近有这个问题。

<Text style={styles.textRegister}> ──────── Register With ────────</Text> 

这个结果:

Image

+1

这并不好 –

0

我做了这个样子。希望这有助于

<View style={styles.hairline} /> 
<Text style={styles.loginButtonBelowText1}>OR</Text> 
<View style={styles.hairline} /> 

样式:

hairline: { 
    backgroundColor: '#A2A2A2', 
    height: 2, 
    width: 165 
}, 

loginButtonBelowText1: { 
    fontFamily: 'AvenirNext-Bold', 
    fontSize: 14, 
    paddingHorizontal: 5, 
    alignSelf: 'center', 
    color: '#A2A2A2' 
}, 
0

您也可以尝试react-native-hr-component

npm i react-native-hr-component --save 

您的代码:

import Hr from 'react-native-hr-component' 

//.. 

<Hr text="Some Text" fontSize={5} lineColor="#eee" textPadding={5} textStyles={yourCustomStyles} hrStyles={yourCustomHRStyles} />