[RN] ๐Ÿงถ ์ปค์Šคํ…€ ํฐํŠธ ์ ์šฉํ•˜๊ธฐ (otf, ttf ํŒŒ์ผ)

TATAยท2024๋…„ 5์›” 17์ผ
0

React-Native

๋ชฉ๋ก ๋ณด๊ธฐ
8/12

โ–ท React-Native์— Font ์ ์šฉํ•˜๊ธฐ

src/assets/fonts์— ์›ํ•˜๋Š” ํฐํŠธ์˜ ttfํŒŒ์ผ๋“ค ๋„ฃ๊ธฐ

react-native.config.js

module.exports = {
  assets: ['src/assets/fonts'],
};

ํ„ฐ๋ฏธ๋„์— ์•„๋ž˜ ๋ช…๋ น์–ด ์ž…๋ ฅ

npx react-native-asset

android ์—์„œ๋Š” android/app/src/main/assets/fonts์— ํฐํŠธ๋“ค์ด ์ž˜ ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ ,
ios ์—์„œ๋Š” Info.plist ํŒŒ์ผ์— UIAppFonts๊ฐ€ ์ œ๋Œ€๋กœ ๋“ค์–ด๊ฐ”๋Š”์ง€ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.

// ํฐํŠธ ์ ์šฉํ•˜๊ธฐ
<Text style={{fontFamily: 'NanumSquareNeo-dEb'}}>
  tata-v
</Text>

๐Ÿงถ tailwind์— ์ ์šฉํ•˜๊ธฐ

tailwind.config.js

module.exports = {
  content: ['./App.{js,jsx,ts,tsx}', './src/**/*.{js,jsx,ts,tsx}', './public/**/*.{js,jsx,ts,tsx,html}'],
  theme: {
    fontFamily: {
      PTDBlack: ['Pretendard-Black'],
      PTDBold: ['Pretendard-Bold'],
      PTDExtraBold: ['Pretendard-ExtraBold'],
      PTDExtraLight: ['Pretendard-ExtraLight'],
      PTDLight: ['Pretendard-Light'],
      PTDMedium: ['Pretendard-Medium'],
      PTDRegular: ['Pretendard-Regular'],
      PTDSemiBold: ['Pretendard-SemiBold'],
      PTDThin: ['Pretendard-Thin'],
      UhBeeBold: ['UhBee-Bold'],
      UhBee: ['UhBee'],
    },
  },
  ...

์ ์šฉํ•˜๋Š” ๊ณณ

<Text className="font-PTDBlack">Go To SignIn</Text>

๐Ÿงถ StyleSheet์— ์ ์šฉํ•˜๊ธฐ

src/style/font.style.js

import { StyleSheet } from 'react-native';

export const font = StyleSheet.create({
  nanum400: {
    fontFamily: 'NanumSquareNeo-aLt',
  },
  nanum500: {
    fontFamily: 'NanumSquareNeo-bRg',
  },
  nanum700: {
    fontFamily: 'NanumSquareNeo-cBd',
  },
  nanum800: {
    fontFamily: 'NanumSquareNeo-dEb',
  },
  nanum900: {
    fontFamily: 'NanumSquareNeo-eHv',
  },
});

์ ์šฉํ•˜๋Š” ๊ณณ

<Text style={font.nanum800} className="mt-[32px]  text-gray900 text-xl">
  tata-v
</Text>

์ปค์Šคํ…€ Text ์ปดํฌ๋„ŒํŠธ

import React from 'react';
import { Text, TextProps } from 'react-native';

interface CustomTextProps extends TextProps {}

const CustomText: React.FC<CustomTextProps> = ({ style, ...rest }) => {
  const customStyle = {
    fontFamily: 'Pretendard-Regular',
    color: '#000000'
  };
  
  return <Text style={[customStyle, style]} {...rest} />;
};

โ—๏ธ ๋งŒ์•ฝ ios์— ํฐํŠธ๊ฐ€ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด

src/assets/fonts์— ์ €์žฅ๋œ ํฐํŠธ ํŒŒ์ผ์˜ ์ด๋ฆ„์ด PostScript ์ด๋ฆ„๊ณผ ์ผ์น˜ํ•˜์ง€ ์•Š์œผ๋ฉด ํฐํŠธ๊ฐ€ ์ œ๋Œ€๋กœ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.

ํฐํŠธ ํŒŒ์ผ ์ด๋ฆ„์„ PostScript ์ด๋ฆ„๊ณผ ๋™์ผํ•˜๊ฒŒ ๋ณ€๊ฒฝํ•ด์•ผ ํ•œ๋‹ค.

profile
๐ŸŒฟ https://www.tatahyeonv.com

0๊ฐœ์˜ ๋Œ“๊ธ€