텍스트 표시와 글꼴 스타일 지정
Text 컴포넌트로 텍스트를 렌더링하고 fontSize, fontWeight, color, lineHeight 스타일을 적용하며 여러 줄 콘텐츠를 자연스럽게 처리합니다.
텍스트 표시와 글꼴 스타일 지정은(는) CoddyKit의 무료 React Native Academy 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 React Native Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
The Text Component Basics
In React Native, every word lives inside a Text component. Loose strings outside one will crash — so Text wraps all the text you show.
import { View, Text } from 'react-native';
export default function Greeting() {
return (
<View>
<Text>Hello, World!</Text>
{/* This would cause an error: */}
{/* Hello, World! ← raw string outside Text */}
</View>
);
}fontSize and fontWeight
Size text with fontSize (a number) and thickness with fontWeight like "bold" or "600". Custom fonts may only have some weights, so test on a real device.
import { Text, View, StyleSheet } from 'react-native';
export default function Typography() {
return (
<View style={{ padding: 16 }}>
<Text style={styles.h1}>Heading 1</Text>
<Text style={styles.h2}>Heading 2</Text>
<Text style={styles.body}>Regular body text for paragraphs.</Text>
<Text style={styles.caption}>Small caption text</Text>
</View>
);
}
const styles = StyleSheet.create({
h1: { fontSize: 32, fontWeight: '700', color: '#111' },
h2: { fontSize: 24, fontWeight: '600', color: '#333' },
body: { fontSize: 16, fontWeight: '400', color: '#555', lineHeight: 24 },
caption: { fontSize: 12, fontWeight: '300', color: '#999' },
});color and lineHeight
Set the text color with a hex or named value, and use lineHeight to space lines apart. A little breathing room makes longer text far easier to read.
import { Text, StyleSheet } from 'react-native';
export default function Article() {
return (
<Text style={styles.paragraph}>
React Native brings the best parts of mobile development
together, combining a smooth native experience with the
speed of JavaScript development.
</Text>
);
}
const styles = StyleSheet.create({
paragraph: {
fontSize: 16,
color: '#444',
lineHeight: 26, // 26/16 = 1.625× line height
letterSpacing: 0.2, // slight tracking for readability
},
});textAlign and Text Decoration
Position text with textAlign (left, center, right) and dress it up with textDecorationLine for underlines or textTransform for uppercase — just like CSS.
import { Text, View, StyleSheet } from 'react-native';
export default function TextStyling() {
return (
<View style={{ padding: 16 }}>
<Text style={styles.centered}>Centered heading</Text>
<Text style={styles.link}>Tap to visit website</Text>
<Text style={styles.strikethrough}>Old price: $29.99</Text>
<Text style={styles.uppercase}>sale ends tonight</Text>
</View>
);
}
const styles = StyleSheet.create({
centered: { textAlign: 'center', fontSize: 20, fontWeight: 'bold' },
link: { color: '#0066cc', textDecorationLine: 'underline' },
strikethrough: { textDecorationLine: 'line-through', color: '#999' },
uppercase: { textTransform: 'uppercase', letterSpacing: 2, fontSize: 14 },
});Nested Text for Mixed Styles
Nest Text inside Text to mix styles in one line, like a single bold word. Inner Text inherits the parent style and overrides only what you set.
import { Text, View } from 'react-native';
export default function MixedText() {
return (
<View style={{ padding: 16 }}>
<Text style={{ fontSize: 16, color: '#333' }}>
Welcome back,{' '}
<Text style={{ fontWeight: 'bold', color: '#0066cc' }}>
Alice
</Text>
! You have{' '}
<Text style={{ color: 'red', fontWeight: '600' }}>3</Text>
{' '}unread messages.
</Text>
</View>
);
}numberOfLines and ellipsizeMode
Use numberOfLines to cap how many lines show, and ellipsizeMode to add the "..." at the end. Great for list titles that should never wrap forever.
import { Text, View, StyleSheet } from 'react-native';
const longTitle = 'The Complete Guide to Building Production-Ready React Native Applications in 2024';
export default function TruncatedText() {
return (
<View style={{ padding: 16 }}>
<Text numberOfLines={1} ellipsizeMode='tail' style={styles.title}>
{longTitle}
</Text>
<Text numberOfLines={2} ellipsizeMode='tail' style={styles.body}>
{longTitle}
</Text>
</View>
);
}
const styles = StyleSheet.create({
title: { fontSize: 18, fontWeight: 'bold', marginBottom: 8 },
body: { fontSize: 14, color: '#666' },
});Loading Custom Fonts with expo-font
Want your own font? Drop a .ttf in assets, then load it with the useFonts hook from expo-font. Wait until it is ready to avoid a flash of plain text.
import { useFonts } from 'expo-font';
import { Text, View } from 'react-native';
export default function App() {
const [fontsLoaded] = useFonts({
'Poppins-Regular': require('./assets/fonts/Poppins-Regular.ttf'),
'Poppins-Bold': require('./assets/fonts/Poppins-Bold.ttf'),
});
if (!fontsLoaded) return null; // Show splash or null while loading
return (
<View style={{ padding: 24 }}>
<Text style={{ fontFamily: 'Poppins-Bold', fontSize: 24 }}>
Custom Font Heading
</Text>
<Text style={{ fontFamily: 'Poppins-Regular', fontSize: 16 }}>
Body text with Poppins Regular.
</Text>
</View>
);
}Google Fonts with @expo-google-fonts
Even easier: the @expo-google-fonts packages bundle any Google Font for you. Install one, import the hook, and use its name — no manual files needed.
import { useFonts, Inter_400Regular, Inter_700Bold } from '@expo-google-fonts/inter';
import { Text, View } from 'react-native';
export default function App() {
const [fontsLoaded] = useFonts({
Inter_400Regular,
Inter_700Bold,
});
if (!fontsLoaded) return null;
return (
<View style={{ padding: 24 }}>
<Text style={{ fontFamily: 'Inter_700Bold', fontSize: 24 }}>
Inter Bold
</Text>
<Text style={{ fontFamily: 'Inter_400Regular', fontSize: 16 }}>
Inter Regular body text.
</Text>
</View>
);
}Selectable Text and onPress
By default Text cannot be copied. Add the selectable prop to allow it, or an onPress handler to make a word act like a tappable link.
import { Text, View, Alert } from 'react-native';
export default function InteractiveText() {
return (
<View style={{ padding: 16 }}>
{/* Selectable text (user can copy) */}
<Text selectable style={{ fontSize: 14, color: '#333', marginBottom: 16 }}>
Long-press to select and copy this text.
</Text>
{/* Tappable text link */}
<Text
style={{ color: '#0066cc', fontSize: 16 }}
onPress={() => Alert.alert('Link tapped!')}
accessibilityRole='link'
>
Terms and Conditions
</Text>
</View>
);
}Handling Multiline and Long Content
Text wraps on its own when it runs out of room. Inside a flex row, add flexShrink: 1 so a long line shrinks instead of pushing things off screen.
import { Text, View, StyleSheet, ScrollView } from 'react-native';
export default function Article() {
return (
<ScrollView contentContainerStyle={{ padding: 16 }}>
<View style={styles.row}>
<Text style={styles.label}>Title:</Text>
{/* flexShrink prevents overflowing the row */}
<Text style={styles.value} numberOfLines={1}>
A Very Long Article Title That Would Otherwise Overflow
</Text>
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
row: { flexDirection: 'row', alignItems: 'center', gap: 8 },
label: { fontWeight: 'bold', color: '#333' },
value: { flexShrink: 1, color: '#666' },
});Text Accessibility: accessibilityLabel
For screen reader users, add an accessibilityLabel to Text that is not self-explanatory. It helps VoiceOver and TalkBack describe your app clearly.
import { Text, View, TouchableOpacity } from 'react-native';
export default function AccessibleText() {
return (
<View>
{/* Screen reader will say: 'Alice, 5 unread messages' */}
<View accessible accessibilityLabel='Alice, 5 unread messages'>
<Text style={{ fontWeight: 'bold' }}>Alice</Text>
<Text style={{ color: 'red' }}>5</Text>
</View>
<TouchableOpacity
accessibilityLabel='Delete account'
accessibilityHint='Double tap to permanently delete your account'
>
<Text style={{ color: 'red' }}>Delete</Text>
</TouchableOpacity>
</View>
);
}Quick Check
Quick check! Lock in what you learned about Text and fonts. ✨
Lesson Recap
Great job! All text lives in Text, fontSize and color shape it, and expo-font makes custom typefaces easy. Next up: showing images.
자주 묻는 질문
“텍스트 표시와 글꼴 스타일 지정” 강의는 무료인가요?
네 — “텍스트 표시와 글꼴 스타일 지정” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 React Native Academy 강의 전체를 잠금 해제할 수 있습니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
“텍스트 표시와 글꼴 스타일 지정”에서 뭘 배우나요?
Text 컴포넌트로 텍스트를 렌더링하고 fontSize, fontWeight, color, lineHeight 스타일을 적용하며 여러 줄 콘텐츠를 자연스럽게 처리합니다. 브라우저에서 직접 실행하는 실습 코드로 React Native Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
React Native Academy을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 React Native Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“텍스트 표시와 글꼴 스타일 지정” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 React Native Academy 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 React Native Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 컨테이너로 사용하는 View 컴포넌트
- 텍스트 표시와 글꼴 스타일 지정
- 로컬 및 원격 소스의 이미지 표시
- 간단한 프로필 카드 구성