본문 바로가기
Dev/RN

4. [RN] 스타일 꾸미기

by VIPeveloper 2021. 1. 26.
반응형

이번 포스팅에서는 스타일을 꾸며보도록 하겠습니다.

저번 포스팅에서 hello world를 띄우기 완료했다면, 그 소스를 그대로 가지고와서 style 설정을 진행해줍니다.

코드는 web이랑 크게 다른 것 같지 않습니다,.

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React,{Component} from 'react';
import { View,Text, StyleSheet } from 'react-native';

class App extends Component{
  render(){
    return (
      <View style={styles.mainView}>
        <View>
          <Text>hello world</Text>
        </View>
        <View>
          <Text>hello world</Text>
        </View>
        <View>
          <Text>hello world</Text>
        </View> 
      </View>
    )
  }
}

const styles = StyleSheet.create({
  mainView: {
    flex: 1,
    backgroundColor: 'green',
    alignItems: 'center',
    justifyContent: 'center'
  }
})

export default App;

flex : 하나의 폰 안에서 비율을 구하는 것입니다.

칸을 나눠주는 것이라고 생각하면 될듯.

화면에 스타일이 잘 적용된 것을 볼 수 있습니다,

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React,{Component} from 'react';
import { View,Text, StyleSheet } from 'react-native';

class App extends Component{
  render(){
    return (
      <View style={styles.mainView}>
        <View style={styles.subView}>
          <Text style={styles.mainText}>hello world</Text>
        </View>
        <View style={styles.subView}>
          <Text>hello world</Text>
        </View>
        <View style={styles.anotherView}>
          <Text style={styles.mainText}>hello world</Text>
        </View> 
      </View>
    )
  }
}

const styles = StyleSheet.create({
  mainView: {
    flex: 1,
    paddingTop: 50,
    backgroundColor: 'green',
    alignItems: 'center',
    justifyContent: 'center'
  },
  subView: {
    flex: 1,
    backgroundColor: 'yellow',
    marginBottom: 10
  },
  anotherView: {
    flex: 2,
    backgroundColor: 'yellow',
    marginBottom: 10 ,
    width: '100%',
    alignItems: 'center',
    justifyContent: 'center'
  },
  mainText:{
    fontSize: 20,
    fontWeight: 'bold',
    color: 'red',
    padding: 20
  }
})

export default App;

ㄴ이것저것 만져서 더 멋진 앱을 구상해볼 수 있습니다.

더 멋진앱!

 

 

끝.

 

 

 

 

 

반응형

'Dev > RN' 카테고리의 다른 글

6. [RN] state, props를 이용해 데이터 전달하기  (0) 2021.01.28
5. [RN] 조각 붙이기  (0) 2021.01.27
3. [RN] Hello world! 띄우기  (0) 2021.01.25
2. [RN] 프로젝트 만들기  (0) 2021.01.23
1. RN 환경설정하기  (0) 2021.01.17