A SwiftUI package that adds converts a UITextField and UITextView to a SwiftUI version of a TextField and TextEditor view with added functionality.
A replacement option for a SwiftUI TextField
Adds a new style case which is roundedBoderWithBackground(color:)
where you can provide a color to use as the background color.
Adds keyboard Toolbar buttons.
Adds a button that will present the scan text from camera option for all content types except for those specific contentTypes that will filter specifically for that content when scanned with camera. When used, the cameral will not enter scanned text into the text view until the insert button is tapped.
A button, that when tapped will dismiss the keyboard.
Note: ScanTextField must have a frame height applied.
VStack {
ScanTextField("Name", text: $name)
.textContentType(.name)
.keyboardType(.alphabet)
.textFieldStyle(.roundedBorder)
.foregroundColor(.red)
.frame(height:30)
ScanTextField("Company", text: $company)
.textFieldStyle(.roundedBorderWithBackground(.quaternarySystemFill))
.frame(height:30)
VStack {
ScanTextField("Email Address", text: $email)
.textContentType(.emailAddress)
.keyboardType(.emailAddress)
ScanTextField("Phone Number", text: $phoneNumber)
.textContentType(.telephoneNumber)
.keyboardType(.phonePad)
}
.frame(height: 60)
Spacer()
}
A replacement option for a SwiftUI TextEditor
Adds 3 style cases
roundedBoder
: a 1 pixel rounded border around the viewroundedBoderWithBackground(color:)
: a 1pixel rounded barder with specified color background.plain
: no style decoration applied (default)
Adds keyboard Toolbar buttons.
A button, that when tapped will dismiss the keyboard.
VStack {
HStack {
ScanTextEditor("Example 1", text: $text)
.frame(height: 120)
ScanTextEditor("Example 2", text: $text2)
.scanTextEditorStyle(.roundedBorder)
.frame(height: 120)
}
ScanTextEditor("Example 3", text: $text3)
.scanTextEditorStyle(.roundedBorderWithBackground(.quaternarySystemFill))
.frame(height: 120)
Spacer()
}
.padding()
}
You can watch this YouTube tutorial to learn all about the scan to camera feature of iOS 15 along with the implementation of CTScanText and how you can modify the package to meet your own needs.
CTScanText is SwiftPM-compatible.
To install, add this package to your Package.swift
or your Xcode project.