Devlog
article thumbnail
Published 2021. 8. 21. 06:24
[SwiftUI fundamental Tutorial] Text 강의/etc

위 글은 유튜브 정대리님의 SwiftUI fundamental Tutorial 강좌를 보고 작성한 정리글로

자세한 내용은 유튜브를 통해 확인하시길 권장합니다. 

 

 

데모 더미 텍스트 사이트: Lorem ipsum

예시 텍스트 구하기

https://www.lipsum.com/

 

Lorem Ipsum - All the facts - Lipsum generator

What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type spec

www.lipsum.com

 

 

 

 

import SwiftUI

struct ContentView: View {
    
   static let dateFormat: DateFormatter = {
       let formatter = DateFormatter()
       formatter.dateFormat = "YYYY년 M월 d일"
       //formatter.dateStyle = .long
       return formatter
}()
    
    var today = Date()
    
    var TrueorFalse : Bool = false
    
    var Number : Int = 123
    
    var body: some View {
        VStack{
        Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. ")
            
            .tracking(1)
            
            .font(.system(.body, design: .rounded))
            .fontWeight(.medium)
            
            .multilineTextAlignment(.center)
        
            
            .lineLimit(nil)
            
            .lineSpacing(10)
            
            .truncationMode(.middle)
            
            .shadow(color: .red, radius: 1.5, x: -10.0, y: 10.0)
            
            
            .padding(20)
            .background(Color.yellow)
            //padding 밖에다가는 적용 안됨
            .cornerRadius(20)
            
            //중첩 padding
            .padding()
            .background(Color.green)
            .cornerRadius(20)
            
            .padding()
            //데이터를 스트링으로 해서 formatter를 이용하여 텍스트로 출력
            Text("오늘의 날짜는 \(today, formatter: ContentView.dateFormat)")
            
            //bool 타입은 string으로 형변환하여 출력
            Text("T or F \(String(TrueorFalse))")
            
            Text("\(Number)")
            
        Text("안녕하세요!!")
            .background(Color.gray)
            .foregroundColor(Color.white)
            
        }
    }
}

dateFormat: 날짜를 보여주기 위함

선언과 동시에 정의됨

static let dateFormat: DateFormatter = {

    let formatter = DateFormatter()

    formatter.dateFormat = "YYYY년 M월 d일"

    return formatter

}()

 

formatter.dateStyle(): formatter.dateFormat = "YYYY년 M월 d일"부분을 SwiftUI에 정의된 형식으로 표현 가능, 핸드폰에 설정된 언어의 형식을 따름

 

 

SwiftUI에서 문자열 출력: \()

 

 

Bool타입은 String으로 감싸서 인스턴스를 만들어줘야 함(형변환 필요) 

 

 

padding 효과 관련: veritcal( 위아래 값 주기), horizontal(양 옆으로 값 주기)

text 효과 관련

.tracking(): 글자와 글자 사이의 간격 설정(글자 밑에서 사용해야 함)

.multilineTextAlignment(위치): 글자 정렬 (default: leading)

.lineLimit(): 문장 수 제한 (ex: .lineLimit(nil): 멀티 라인)

.lineSpacing(): 글자와 글자 사이의 거리

.truncationMode(): 글자 수 요약

.shadow(color, radius, x, y): 글자 그림자

 

 

 

 

 

'강의 > etc' 카테고리의 다른 글

[SwiftUI fundamental Tutorial] Stack  (0) 2021.08.23
[SwiftUI fundamental Tutorial] Image  (0) 2021.08.22
[SwiftUI fundamental Tutorial] WebView  (0) 2021.08.20
[SwiftUI fundamental Tutorial] Binding  (0) 2021.08.20
[SwiftUI fundamental Tutorial] State  (0) 2021.08.20
profile

Devlog

@덩이

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그