2017-04-12 122 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} />