iOS/SwiftUI
TextField 커스텀 PlaceHolder 넣기
Hamp
2025. 8. 28. 21:26
반응형

🏁 학습할 내용
- promt 파라미터
- 커스텀 플레이스홀더
🐳 prompt란
🎯 역할

간단하게 요약하면, 입력되야할 내용에 대한 guide 즉, placeHolder 역할을 한다고 한다.
✅ 커스텀 플레이스홀더
실제 내용과 다른 폰트 다른 색깔을 적용하고 싶다면, prompts를 이용하면된다.

중요한점은 반드시 Text여야함, some View 형태로 들어가면 안됨!
여기서, 재밌었던 점은 포커싱 됐을 때, 깜빡거리는 커서의 크기는 content의 크기를 따라간다는 점

VStack {
TextField("", text: $text, prompt: Text("PlaceHolder").foregroundStyle(.red).font(.title))
.font(.caption)
.padding(.vertical)
.padding(.horizontal)
.background(.green)
}
출처
https://developer.apple.com/documentation/swiftui/textfield
TextField | Apple Developer Documentation
A control that displays an editable text interface.
developer.apple.com
반응형