React Native初探:
RN内置了Touchable*
可用来生成按钮。例如:
Button1
就差自定义样式了。
1、react-native-button库
里做了简单的封装。
npm install react-native-button --save
代码示例:
import React, { Component } from 'react';import { AppRegistry, StyleSheet, Text, View, TouchableHighlight} from 'react-native';import Button from 'react-native-button';class MyReactNativeProject extends Component { _onPressButton() { console.log("You tapped the button!"); } _onPressButton2() { console.log('Pressed!'); } render() { return (); }}const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', },});AppRegistry.registerComponent('MyReactNativeProject', () => MyReactNativeProject); Button1
效果图:
2、react-native-awesome-button库
这个更像按钮。