[iOS] UILabel 주요 속성 정리

2025. 6. 25. 21:03·📱 iOS
-->

1. font


텍스트의 글꼴(Font)과 크기(size)를 지정한다.

 

.boldSystemFont(ofSize:), .systemFont(ofSize:), 커스텀 폰트도 사용이 가능하다.

label.font = UIFont.boldSystemFont(ofSize: 16) // 볼드체
label.font = UIFont.systemFont(ofSize: 16) // 시스템 폰트
label.font = UIFont(name: "BMDOHYEON", size: 16) // 커스텀 폰트

 

2. text


레이블에 표시할 문자열(String)을 설정한다.

label.text = "Hello, Swift!"

 

숫자 같이 쓰려면 "\(변수)원" 처럼 문자열 보간 사용

let price = 3000
label.text = "\(price)원"

 

3. textColor


텍스트 색상을 지정할 수 있다.

  • 기본 색: .black, .white, .gray, .red, .blue 등.
    • 고정된 색상
    • 다크모드 여부와 상관없이 항상 같은 색 (다크모드에서도 검정색 그대로)
label.textColor = .black

 

  • iOS 시스템 색상 스타일: .systemBlue, .systemRed, .systemGray
    • iOS 디자인 가이드에 맞춘 색상
    • 기본 색처럼 보이지만, iOS에서 일관된 테마를 유지할 수 있도록 설계됨
    • 다크모드에 자연스럽게 어울리는 색상으로 조정됨
label.textColor = .systemBlue // 다크모드에서도 자연스럽게 보임

 

  • 다크모드 대응 색상: .label, .secondaryLabel
    • 텍스트 전용 컬러
    • iOS가 라이트/다크 모드에 맞게 자동으로 색을 변경해줌
    • .label: 주 텍스트 (라이트 모드: 검정 / 다크 모드: 흰색)
    • .secondaryLabel: 보조 텍스트 (라이트 모드: 연한 회색 / 다크 모드: 더 연한 회색)
label.textColor = .label
label.textColor = .secondaryLabel

 

4. textAlignment


텍스트 정렬 방식을 설정한다.

  • .left: 왼쪽 정렬 (기본)
  • .center : 가운데 정렬
  • .right: 오른쪽 정렬
  • .justified: 양쪽 정렬 (문단 느낌)
  • .natural: 언어 방향에 따라 (한글: left, 아랍어: right)
label.textAlignment = .center

 

5. numberOfLines (줄 수 제한)


레이블이 표시할 최대 줄 수를 설정한다.

label.numberOfLines = 2 // 최대 2줄까지
label.numberOfLines = 0 // 제한 없이 모든 줄 표시

 

6. lineBreakMode (줄 바꿈 / 말줄임표 처리)


줄이 잘릴 때 어떻게 처리할지 정함.

  • .byTruncatingTail: 마지막 줄 끝에서 … 처리 (Tail)
  • .byTruncatingHead: 첫 부분을 … 처리 (Head)
  • .byClipping: 그냥 잘림 … 없음
  • .byWordWrapping: 단어 단위 줄바꿈
  • .byCharWrapping: 글자 단위 줄바꿈
label.lineBreakMode = .byTruncatingTail

 

 

 

'📱 iOS' 카테고리의 다른 글

[iOS] SnapKit의 제약 설정 메서드 + 예시 코드  (0) 2025.07.02
[iOS] Auto Layout 우선순위(Priority)  (2) 2025.06.24
[iOS] Auto Layout - UIScrollView와 LayoutGuide 정리  (0) 2025.06.23
CodingKey로 JSON 키 매핑하기  (0) 2025.06.19
Xcode에서 시뮬레이터 추가하는 방법  (0) 2025.06.18
'📱 iOS' 카테고리의 다른 글
  • [iOS] SnapKit의 제약 설정 메서드 + 예시 코드
  • [iOS] Auto Layout 우선순위(Priority)
  • [iOS] Auto Layout - UIScrollView와 LayoutGuide 정리
  • CodingKey로 JSON 키 매핑하기
MoriOS
MoriOS
기억하기 위해 기록하는 공간 🖋️
  • MoriOS
    MoriOS
    MoriOS
  • 전체
    오늘
    어제
    • 분류 전체보기 (67)
      • 📌 Swift (12)
      • 📱 iOS (11)
      • 💡 Algorithm (1)
      • ❕Data structure (4)
      • 🪙 Python (0)
      • ⚙️ Git (3)
      • 🖋️ TIL Journal (33)
      • 📝 Etc (3)
  • 블로그 메뉴

    • GitHub
  • 인기 글

  • 태그

    셀 높이
    weak
    TiL
    커밋 아이콘
    prepareconstraints
    Components
    remakeconstraints
    updateconstraints
    swift cow
    후행클로저
    uikit
    스크롤 길이
    cow 값 타입
    makeconstraint
    cow 쓰기 복사
    Codable
    프로그래머스
    static
    cow 참조 타입
    swift optional
    제약조건 변경
    커밋 이모지
    GitHub
    git moji
    Split
    제약조건 수정
    SnapKit
    Optional
    ios
    swift
  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
MoriOS
[iOS] UILabel 주요 속성 정리
상단으로

티스토리툴바