React-Native TextInput組件詳解及實例代碼
更新時間:2016年10月08日 10:14:02 作者:順子_RTFSC
這篇文章主要介紹了React-Native TextInput組件詳解及實例代碼的相關資料,需要的朋友可以參考下
同時適配Android和IOS

代碼注釋比較詳細
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TextInput,
Platform,
TouchableOpacity,
} from 'react-native';
//獲取屏幕信息
var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
class TextInputG extends Component {
render() {
return (
<View style={styles.container}>
{/*賬號輸入框在這里用View包裹以便處理器樣式*/}
<View style={styles.textInputViewStyle}>
<TextInput
style={styles.textInputStyle}
//站位符
placeholder='手機號'/>
</View>
{/*密碼輸入框*/}
<View style={styles.textInputViewStyle}>
<TextInput
style={styles.textInputStyle}
placeholder='密碼'
//密文
secureTextEntry={true}/>
</View>
{/*設置控件可點擊*/}
<TouchableOpacity onPress={()=>{alert('點擊登錄')}}>
{/*登錄按鈕*/}
<View style={styles.textLoginViewStyle}>
<Text style={styles.textLoginStyle}>登錄</Text>
</View>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
//設置占滿屏幕
flex: 1,
// backgroundColor: 'black',
marginTop: 140,
},
//包裹輸入框View樣式
textInputViewStyle: {
//設置寬度減去30將其居中左右便有15的距離
width: width - 30,
height: 45,
//設置圓角程度
borderRadius: 18,
//設置邊框的顏色
borderColor: 'blue',
//設置邊框的寬度
borderWidth: 1,
//內(nèi)邊距
paddingLeft: 10,
paddingRight: 10,
//外邊距
marginTop: 10,
marginLeft: 20,
marginRight: 20,
//設置相對父控件居中
alignSelf: 'center',
},
//輸入框樣式
textInputStyle: {
width: width - 30,
height: 35,
paddingLeft: 8,
backgroundColor: '#00000000',
// alignSelf: 'center',
//根據(jù)不同平臺進行適配
marginTop: Platform.OS === 'ios' ? 4 : 8,
},
//登錄按鈕View樣式
textLoginViewStyle: {
width: width - 30,
height: 45,
backgroundColor: 'red',
borderRadius: 20,
marginTop: 30,
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center',
},
//登錄Text文本樣式
textLoginStyle: {
fontSize: 18,
color: 'white',
},
});
module.exports = TextInputG;
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
淺析JS中什么是自定義react數(shù)據(jù)驗證組件
我們在做前端表單提交時,經(jīng)常會遇到要對表單中的數(shù)據(jù)進行校驗的問題。這篇文章主要介紹了js中什么是自定義react數(shù)據(jù)驗證組件,需要的朋友可以參考下2018-10-10
react+redux的升級版todoList的實現(xiàn)
本篇文章主要介紹了react+redux的升級版todoList的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-12-12
使用React和Redux Toolkit實現(xiàn)用戶登錄功能
在React中,用戶登錄功能是一個常見的需求,為了實現(xiàn)該功能,需要對用戶輸入的用戶名和密碼進行驗證,并將驗證結果保存到應用程序狀態(tài)中,在React中,可以使用Redux Toolkit來管理應用程序狀態(tài),從而實現(xiàn)用戶登錄功能,需要詳細了解可以參考下文2023-05-05
基于Cloud?Studio構建React完成點餐H5頁面(騰訊云?Cloud?Studio?實戰(zhàn)訓練營)
最近也是有機會參與到了騰訊云舉辦的騰訊云Cloud Studio實戰(zhàn)訓練營,借此了解了騰訊云Cloud?Studio產(chǎn)品,下面就來使用騰訊云Cloud?Studio做一個實戰(zhàn)案例來深入了解該產(chǎn)品的優(yōu)越性吧,感興趣的朋友跟隨小編一起看看吧2023-08-08

