Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- ios
- modern concurrency
- 오블완
- modern concurrency deep dive
- SWIFT
- 티스토리챌린지
- WWDC
- APNS
- 야곰 # 야곰아카데미커리어스타터캠프 #iOS개발자 # 부트캠프
Archives
- Today
- Total
Geon
TextEditor에 PlaceHolder 적용 본문
TextEditor 에는 PlaceHolder를 적용할수 없습니다.(지원하지 않음)
FocustState(iOS 15+) 를 사용하지 못할때 TextEditor에 placeHoler를 적용하고 싶을경우에 사용할수 있습니다.
import SwiftUI
import Foundation
struct ContentView: View {
@State var message: String = "placeHolder Message"
let deviceSize = CGSize(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
var body: some View {
VStack(spacing: 20) {
Text("텍스터 에디터")
TextEditor(text: $message)
.font(Font.system(size: 14, weight: .regular, design: .default))
.textFieldStyle(PlainTextFieldStyle())
.onAppear(perform: {
// placeHoler 적용
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) { (noti) in
withAnimation {
if self.message == "placeHolder Message" {
self.message = ""
}
}
}
// 변경 없을떄
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { (noti) in
withAnimation {
if self.message == "" {
self.message = "placeHolder Message"
}
}
}
}).background(RoundedRectangle(cornerRadius: 5).stroke(style: StrokeStyle(lineWidth: 5)))
}
.frame(height: deviceSize.height / 3)
Button {
print("")
} label: {
Text("Touched")
}
}
}
실행 화면 |
![]() |
'SwiftUI > 지식 창고' 카테고리의 다른 글
mitmproxy로 iOS 네트워크 감청해보기 (1) | 2024.09.05 |
---|---|
긴급 심사 올리기 (0) | 2024.08.21 |
NotificationService를 통한 다국어 처리 (0) | 2024.06.25 |
Json Parsing with optional key (0) | 2023.02.02 |
SwiftUI 텍스트 크기 지정 (0) | 2022.12.14 |