macOS, iOS
[SwiftUI] UITextView대신 TextEditor
SweetDev
2021. 3. 24. 11:27
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()
}