티스토리 뷰

SwiftUI에서 기존의 UITextView같은 역할을 하는 TextEditor!!

근데 10년이 지난 지금도 역시나 TextEditor에 Placeholder는 없다...애플 대체 뭐함??????????

 

import SwiftUI

struct ContentView: View {
    
    @State private var text = "Hello world"
    
    var body: some View {
        TextEditor(text: $text)
    }
}

구현은 매우 간단하다. 

 

나처럼 Placeholder가 필요한 사람은..

  @State var placeholderText: String = "여행 꿀팁을 입력해주세요"
  @State var content: String = ""

  ZStack {
          if self.content.isEmpty {
            TextEditor(text: $placeholderText)
              .font(.body)
              .foregroundColor(.gray)
              .disabled(true)
              .padding()
          }
          TextEditor(text: $content)
            .font(.body)
            .opacity(self.content.isEmpty ? 0.25 : 1)
            .padding()
        }

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함