상세 컨텐츠

본문 제목

폰트 커스텀 react native

react-native-tool

by RNDK 2023. 6. 28. 11:32

본문

*주의!!!!!!
이 글을 읽기전 본인의 react native 프로젝트가 0.6버전 이상인지 확인하고 적용할 것!

//폰트타입
type CTProps = {
fontName?: string;
color?: string;
size?: number;
};

/**
* @param fontName 폰트이름
* @param color 색상
* @param size 사이즈
* @description 폰트커스텀
*/
export const CT = styled.Text<CTProps>`
font-size: ${props => props.size || 20}px;
color: ${props => props.color || '#000'};
font-family: ${'Georgia'};
`;

폰트 적용 방법은 아래 참고

루트 -> src -> assets -> font 안에 폰트 관련 파일들을 넣어준다 (확장자는 보통 ttf입니다.)

루트에 react-native.config.js 파일이 없다면 생성 그 안에 아래에 코드를 복사 붙여넣기를 해준다~

 

module.exports = {
project: {
ios: {},
android: {}, // grouped into "project"
},
assets: ['./src/assets/font'], // stays the same
};

 

저장 후

npx react-native link

혹은

$ yarn react-native link

를 실행해준다. 끝!

관련글 더보기

댓글 영역