A SwiftUI view that can display and edit long-form text or display a prompt when the editor's content is empty.
- Customizable UI: Easily integrate and style the editor as same as
SwiftUI.TextEditor
- Cross-Platform: Compatible with:
- iOS 15.0+
- macOS 12.0+.
- visionOS 1.0+.
- Swift Package Manager: Simple integration via SPM.
Add PromptTextEditor
to your project via Swift Package Manager:
- Open Xcode and go to File > Add Packages.
- Enter the URL of this repository:
https://github.com/tphduy/PromptTextEditor
- Choose the latest version and add the package to your project.
To use PromptTextEditor
, import the module and add the editor to your SwiftUI view.
import PromptTextEditor
struct ContentView: View {
@State private var text: String = ""
var body: some View {
PromptTextEditor(
text: $text,
prompt: Text("How was your day?")
)
}
}
You can provide custom prompt logic and adjust the appearance to suit your application's needs, as same as SwiftUI.TextEditor
.
Starting from iOS 17.0, macOS 14.0, and visionOS 1.0, the PromptTextEditor
applies the placeholder sematic style for prompt
, For example, you can set the foreground style to .pink
as below.
PromptTextEditor(
text: $text,
prompt: Text("How was your day?")
)
.foregroundStyle(.pink)
For older versions of these operating systems, the prompt will default to the third level of the current foreground style .tertiary
.
Applying multiline text alignment will affect both the text and prompt:
PromptTextEditor(
text: $text,
prompt: Text("How was your day?")
)
.multilineTextAlignment(.center)
Applying font will affect both the text and prompt. The same behavior for line limit, line spacing, and so on.
PromptTextEditor(
text: $text,
prompt: Text("How was your day?")
)
.font(.system(size: 60))
Contributions are welcome! If you find a bug or have a feature request, feel free to open an issue or submit a pull request.
PromptTextEditor
is released under the MIT License. See the LICENSE file for more information.