DynamicTextEditor is a SwiftUI-based TextEditor component that automatically adjusts its height according to the user’s input.
Similar to the chat input field in KakaoTalk, where the text field dynamically grows with the number of lines.
🇰🇷 한국어 README | 🇺🇸 English README | 🇯🇵 日本語 README
- ✅ Set maximum line count
- ✅ Support for placeholder text
- ✅ Automatically resizing
TextEditor - ✅ Custom font support
- iOS 15+
- SwiftUI
dependencies: [
.package(url: "https://github.com/winwx/DynamicTextEditor.git", branch: "main")
]import SwiftUI
import DynamicTextEditor
@State var text: String = ""
var body: some View {
DynamicTextEditor("Enter your text...", text: $text)
}import SwiftUI
import DynamicTextEditor
@State var text: String = ""
var body: some View {
...
HStack(alignment: .bottom, spacing: 16) {
DynamicTextEditor(
"Type a message",
text: $text
)
.setFont(uiFont: .systemFont(ofSize: 16))
.setMaxLineCount(8)
.setTextColor(.black)
.setPlaceholderColor(.gray)
.frame(minHeight: 24)
emojiButton()
}
.padding(.vertical, 6)
.padding(.horizontal, 8)
.background(Color.textField_BG)
.cornerRadius(20)
...
}DynamicTextEditor provides a SwiftUI-style modifier API to customize its behavior and appearance.
Sets the font using UIFont.
DynamicTextEditor("Input", text: $text)
.setFont(uiFont: .systemFont(ofSize: 16, weight: .medium))Sets the maximum number of lines. Default is 5.
DynamicTextEditor("Input", text: $text)
.setMaxLineCount(3)Sets the text color. Default is .black.
DynamicTextEditor("Input", text: $text)
.setTextColor(.gray)Sets the placeholder color. Default is .gray.
DynamicTextEditor("Input", text: $text)
.setPlaceholderColor(.black)🧪 Custom Example
DynamicTextEditor("Write a comment...", text: $text)
.setFont(uiFont: .systemFont(ofSize: 14))
.setMaxLineCount(4)
.setTextColor(.blue)
.setPlaceholderColor(.red)
