React-Native TextInput組件詳解及實(shí)例代碼
更新時(shí)間:2016年10月08日 10:14:02 作者:順子_RTFSC
這篇文章主要介紹了React-Native TextInput組件詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
同時(shí)適配Android和IOS
代碼注釋比較詳細(xì)
/** * 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}> {/*賬號(hào)輸入框在這里用View包裹以便處理器樣式*/} <View style={styles.textInputViewStyle}> <TextInput style={styles.textInputStyle} //站位符 placeholder='手機(jī)號(hào)'/> </View> {/*密碼輸入框*/} <View style={styles.textInputViewStyle}> <TextInput style={styles.textInputStyle} placeholder='密碼' //密文 secureTextEntry={true}/> </View> {/*設(shè)置控件可點(diǎn)擊*/} <TouchableOpacity onPress={()=>{alert('點(diǎn)擊登錄')}}> {/*登錄按鈕*/} <View style={styles.textLoginViewStyle}> <Text style={styles.textLoginStyle}>登錄</Text> </View> </TouchableOpacity> </View> ); } } const styles = StyleSheet.create({ container: { //設(shè)置占滿屏幕 flex: 1, // backgroundColor: 'black', marginTop: 140, }, //包裹輸入框View樣式 textInputViewStyle: { //設(shè)置寬度減去30將其居中左右便有15的距離 width: width - 30, height: 45, //設(shè)置圓角程度 borderRadius: 18, //設(shè)置邊框的顏色 borderColor: 'blue', //設(shè)置邊框的寬度 borderWidth: 1, //內(nèi)邊距 paddingLeft: 10, paddingRight: 10, //外邊距 marginTop: 10, marginLeft: 20, marginRight: 20, //設(shè)置相對(duì)父控件居中 alignSelf: 'center', }, //輸入框樣式 textInputStyle: { width: width - 30, height: 35, paddingLeft: 8, backgroundColor: '#00000000', // alignSelf: 'center', //根據(jù)不同平臺(tái)進(jìn)行適配 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;
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
React性能優(yōu)化的實(shí)現(xiàn)方法詳解
react憑借virtual DOM和diff算法擁有高效的性能,除此之外也有很多其他的方法和技巧可以進(jìn)一步提升react性能,在本文中我將列舉出可有效提升react性能的幾種方法,幫助我們改進(jìn)react代碼,提升性能2023-01-01淺析JS中什么是自定義react數(shù)據(jù)驗(yàn)證組件
我們?cè)谧銮岸吮韱翁峤粫r(shí),經(jīng)常會(huì)遇到要對(duì)表單中的數(shù)據(jù)進(jìn)行校驗(yàn)的問題。這篇文章主要介紹了js中什么是自定義react數(shù)據(jù)驗(yàn)證組件,需要的朋友可以參考下2018-10-10react+redux的升級(jí)版todoList的實(shí)現(xiàn)
本篇文章主要介紹了react+redux的升級(jí)版todoList的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12使用React和Redux Toolkit實(shí)現(xiàn)用戶登錄功能
在React中,用戶登錄功能是一個(gè)常見的需求,為了實(shí)現(xiàn)該功能,需要對(duì)用戶輸入的用戶名和密碼進(jìn)行驗(yàn)證,并將驗(yàn)證結(jié)果保存到應(yīng)用程序狀態(tài)中,在React中,可以使用Redux Toolkit來管理應(yīng)用程序狀態(tài),從而實(shí)現(xiàn)用戶登錄功能,需要詳細(xì)了解可以參考下文2023-05-05基于Cloud?Studio構(gòu)建React完成點(diǎn)餐H5頁(yè)面(騰訊云?Cloud?Studio?實(shí)戰(zhàn)訓(xùn)練營(yíng))
最近也是有機(jī)會(huì)參與到了騰訊云舉辦的騰訊云Cloud Studio實(shí)戰(zhàn)訓(xùn)練營(yíng),借此了解了騰訊云Cloud?Studio產(chǎn)品,下面就來使用騰訊云Cloud?Studio做一個(gè)實(shí)戰(zhàn)案例來深入了解該產(chǎn)品的優(yōu)越性吧,感興趣的朋友跟隨小編一起看看吧2023-08-08