Simple use of react-native-vector-icons, images, buttons, label views, navigation bars,

Source: Internet
Author: User

Simple use of react-native-vector-icons, images, buttons, label views, navigation bars,

ICONS allows you to directly use the image name to load the three sides of the image. It is very convenient to use. You do not need to add various images in the project folder, saving a lot of space, let's take a look at how to use it!

1. First open terminal to go to our project folder (do not create a project, please refer to: http://blog.csdn.net/margaret_mo/article/details/51304062)

Input: npm install react-native-vector-icons -- save (Press ENTER)

Input: npm install rnpm-g

Input: rnpm link (Press ENTER)

2. Use Xcode In the Finder to open the project:.../Demo/ios/Demo. xcodeproj

(1) Right-click the project file Add Files to "(your project name )"

(2) Select node_modules/react-native-vector-icons/Fonts File

(3). Click "finish ".


3. In the Info. plist file of xcode, add:Fonts provided by application array, and add the following nine items:

 

Even if the environment is set up, the next step is to use ICONS.

 

4. Right-click the Finder and use Atom to open the project:

 

5. Then we began to edit our program:

 

'use strict';

import React, {
  AppRegistry,
  Component,
  View,
  StyleSheet,
  AlertIOS,
  Text,
  TabBarIOS,
  NavigatorIOS,
} from 'react-native';

var Icon = require ('react-native-vector-icons / FontAwesome');
import FindComponent from './FindComponent';
import SearchComponent from './SearchComponent';


class Demo extends Component {

  state = {
    selectedTab: 'find',
  };

  loginWithFacebook = () => {// Method triggered after clicking "Login with Facebook" button
    AlertIOS.alert ("facebook");
  }

  render () {
    return (
      <View style = {styles.container}>
        <Icon
          name = "rocket" // Picture name link, you can search at this URL: http://ionicons.com/, when in use: remove the "icon-" in front !!!!
          size = {30} // Image size
          color = "red" // Image color
          />

        <Icon.Button // Add text after the picture
          name = "facebook"
          backgroundColor = "# 3b5998"
          onPress = {this.loginWithFacebook} // Method triggered when the button is clicked
          >
          Login with Facebook
        </Icon.Button>

        <Icon.Button // Add after the picture, custom style text
          name = "facebook"
          backgroundColor = "# 3b5998">
          <Text style = {{fontFamily: 'Arial', fontSize: 15}}> Login with Facebook </ Text>
        </Icon.Button>


        <TabBarIOS // Use with tab view
         tintColor = "# 4977f0"
         barTintColor = "# E6E6E6">

         <Icon.TabBarItem // Replace TabBarIOS.Item with Icon.TabBarItem
           title = "found"
           iconName = "home"
           selectedIconName = "home"
           selected = {this.state.selectedTab === 'find'}
           onPress = {() => {
             this.setState ({
               selectedTab: 'find',
             });
           }}>
           <NavigatorIOS // Navigation bar
             style = {styles.container}
             tintColor = '# FFFFFF'
             barTintColor = '# 4977f0'
             initialRoute = {{
               title: "Discover",
               titleTextColor: 'white',
               component: FindComponent
             }} />
         </Icon.TabBarItem>

         <Icon.TabBarItem // Replace TabBarIOS.Item with Icon.TabBarItem
           title = "Search"
           iconName = "search"
           selectedIconName = "search"
           selected = {this.state.selectedTab === 'search'}
           onPress = {() => {
             this.setState ({
               selectedTab: 'search',
             });
           }}>
           <NavigatorIOS
             style = {styles.container}
             tintColor = '# FFFFFF'
             barTintColor = '# 4977f0'
             initialRoute = {{
               title: "Search",
               titleTextColor: 'white',
               component: SearchComponent
             }} />
         </Icon.TabBarItem>
       </ TabBarIOS>

      </ View>
    );
  }
}

const styles = StyleSheet.create ({
  container: {
    flex: 1,
    justifyContent: 'center',
  },
});

AppRegistry.registerComponent ('Demo', () => Demo); 

In the project folder in terminal, enter react-native run-ios (Press ENTER) and wait until the program runs.

 

Main Code: http://download.csdn.net/detail/margaret_mo/9512769

 

 

Reference: https://github.com/oblador/react-native-vector-icons

 

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.