iOS SwiftUI) Text 관련
import SwiftUI
struct ContentView: View {
var body: some View {
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. It has survived not only five centuries, ")
.font(.system(.body, design: .rounded))
.fontWeight(.medium)
.multilineTextAlignment(.center)
.lineLimit(nil)
.padding(.vertical, 20)
.background(Color.yellow)
}
}
.multilineTextAlignment(.center) 가운데 정렬
.lineLimit(nil) = UIKit 에서 numberOfLines = 0 이랑 같음
.padding(.vertical, 20) 아래 위로 패딩 (아래 사진 참고)
.padding(.horizontal, 20) -> 왼쪽 오른쪽에 패딩생김
dateFormatter 쉽게 text로 출력하기
import SwiftUI
struct ContentView: View {
static let dateFormat: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "YYYY년 M월 d일"
return formatter
}()
var today = Date()
var trueOfFalse: Bool = false
var number: Int = 123
var body: some View {
VStack {
Text("안녕하세요!!")
.background(Color.gray)
.foregroundColor(Color.white)
Text("오늘의 날짜입니다.: \(today, formatter: ContentView.dateFormat)")
Text("참 혹은 거짓: \(String(trueOfFalse))")
Text("숫자입니다.: \(number)")
}
}
}
참고) https://www.youtube.com/watch?v=yUnQHE0eChQ&list=PLgOlaPUIbynqyJHiTEv7CFaXd8g5jtogT&index=5
'iOS > SwiftUI' 카테고리의 다른 글
SwiftUI에서 Info.plist 사용 방법 (0) | 2023.10.01 |
---|---|
iOS SwiftUI) List (UIKit의 tableView에 해당) (0) | 2023.02.22 |
iOS SwiftUI) Image (0) | 2023.02.20 |
iOS SwiftUI) WebView 띄우기 (0) | 2023.02.20 |
SwiftUI 기본 정리 (0) | 2023.02.20 |