Anybody know if its doable so as to add a button to Auto Suggestion Bar? Ended up making an attempt the code under and I used to be in a position so as to add a button on prime of the keyboard. However confused if there’s an api that permits us to change autocorrect standing bar.
CustomTextField
import Basis
import UIKit
import SwiftUI
struct CustomTextfield: UIViewRepresentable {
@Binding var textual content: String
var keyType: UIKeyboardType
func makeUIView(context: Context) -> UITextField {
let textfield = UITextField()
textfield.keyboardType = keyType
let toolBar = UIToolbar(body: CGRect(x: 0, y: 0, width: textfield.body.measurement.width, peak: 44))
let doneButton = UIBarButtonItem(title: "Accomplished", fashion: .carried out, goal: self, motion: #selector(textfield.doneButtonTapped(button:)))
toolBar.objects = [doneButton]
toolBar.setItems([doneButton], animated: true)
textfield.leftView = toolBar
return textfield
}
func updateUIView(_ uiView: UITextField, context: Context) {
uiView.textual content = textual content
}
}
extension UITextField{
@objc func doneButtonTapped(button:UIBarButtonItem) -> Void {
self.resignFirstResponder()
}
}
TestView
import Basis
import SwiftUI
struct TestView : View {
@State var textual content = ""
var physique: some View {
CustomTextfield(textual content: $textual content, keyType: UIKeyboardType.asciiCapable)
.body(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 50)
.overlay(
RoundedRectangle(cornerRadius: 16)
.stroke(Shade.blue, lineWidth: 4)
)
}
}