Reputation: 435
This is a iPadOS hardware keyboard assistant bar related question.
I want to do this (app is iA Writer, so it's definitely not a private API)
However, when I try to use
.toolbar {
ToolbarItem(placement: .keyboard) {
// Picker, Button, etc..
}
}
It shows up in an older-style, full-screen bar (which works for iOS, but really out of place for iPadOS).
I searched all over the internet and could not find what I need to do to place toolbar items into the keyboard assistant bar. I might be searching for the wrong terms.
Does anyone know how this is accomplished? iA Writer has done this, the lightning and search icon open up custom functions/menus, so there must be a public API for it.
Appreciate your help!
Upvotes: 2
Views: 84
Reputation: 41
this code is working for me
class MyTextViewController: UIViewController, UITextViewDelegate {
let textView = UITextView()
override func viewDidLoad() {
super.viewDidLoad()
textView.frame = view.bounds
textView.delegate = self
view.addSubview(textView)
configureKeyboardShortcutBar()
}
func configureKeyboardShortcutBar() {
let inputAssistant = textView.inputAssistantItem
inputAssistant.leadingBarButtonGroups = [UIBarButtonItemGroup(barButtonItems: [createButton(title: "Expense"), createButton(title: "Income")], representativeItem: nil)]
inputAssistant.trailingBarButtonGroups = [UIBarButtonItemGroup(barButtonItems: [createButton(title: "Notes")], representativeItem: nil)]
}
func createButton(title: String) -> UIBarButtonItem {
return UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(toolbarButtonTapped(_:)))
}
@objc func toolbarButtonTapped(_ sender: UIBarButtonItem) {
print("\(sender.title ?? "") tapped")
}
}
Upvotes: 1