⌨️ KeyboardToolbar - Add tools above your keyboard with iOS-like keyboard buttons

Related tags

Layout swift ios
Overview

KeyboardToolbar

👀 Overview

Use KeyboardToolbar to add tools as an input accessory view to a UITextField, UITextView, or any other view conforming to UITextInput.

KeyboardToolbar creates buttons with an iOS-like appearance and behavior.

📖 Documentation

The public interface is documented in the Swift files and can be found in KeyboardToolbar/Sources/KeyboardToolbar. You can also read the documention on Swift Package Index.

Lastly, you can also build the documentation yourself by opening the Swift package in Xcode and selecting Product > Build Documentation in the menu bar.

📦 Adding the Package

KeyboardToolbar is distributed using the Swift Package Manager. Install it in a project by adding it as a dependency in your Package.swift manifest or through “Package Dependencies” in project settings.

let package = Package(
    dependencies: [
        .package(url: "[email protected]:simonbs/KeyboardToolbar.git", from: "0.1.0")
    ]
)

🚀 Getting Started

The best way to understand how KeyboardToolbar is integrated into your project is by having a look at the Example project in this repository.

At a high level there are two steps required to setting up the keyboard toolbar.

  1. Create an instance of KeyboardToolbarView and assign it to inputAccessoryView on a UITextField, UITextView, or any other view that conforms to the UITextInput protocol.
  2. Assign an array of KeyboardToolGroup items to the groups property on your instance of KeyboardToolbarView.

The below code snippet shows how the two steps can be performed.

", textView: textView) ]), KeyboardToolGroupItem(representativeTool: InsertTextKeyboardTool(text: "#", textView: textView), tools: [ InsertTextKeyboardTool(text: "#", textView: textView), InsertTextKeyboardTool(text: "\"", textView: textView), InsertTextKeyboardTool(text: "'", textView: textView), InsertTextKeyboardTool(text: "$", textView: textView), InsertTextKeyboardTool(text: "\\", textView: textView), InsertTextKeyboardTool(text: "@", textView: textView), InsertTextKeyboardTool(text: "%", textView: textView), InsertTextKeyboardTool(text: "~", textView: textView) ]) ]), KeyboardToolGroup(items: [ // Tool to present the find navigator. KeyboardToolGroupItem(style: .secondary, representativeTool: BlockKeyboardTool(symbolName: "magnifyingglass") { [weak self] in self?.textView.findInteraction?.presentFindNavigator(showingReplace: false) }), // Tool to dismiss the keyboard. KeyboardToolGroupItem(style: .secondary, representativeTool: BlockKeyboardTool(symbolName: "keyboard.chevron.compact.down") { [weak self] in self?.textView.resignFirstResponder() }) ]) ]">
/// Create our instance of KeyboardToolbarView and pass it to an instance of UITextView.
let keyboardToolbarView = KeyboardToolbarView()
textView.inputAccessoryView = keyboardToolbarView
// Setup our tool groups.
let canUndo = textView.undoManager?.canUndo ?? false
let canRedo = textView.undoManager?.canRedo ?? false
keyboardToolbarView.groups = [
    // Tools for undoing and redoing text in the text view.
    KeyboardToolGroup(items: [
        KeyboardToolGroupItem(style: .secondary, representativeTool: BlockKeyboardTool(symbolName: "arrow.uturn.backward") { [weak self] in
            self?.textView.undoManager?.undo()
            self?.setupKeyboardTools()
        }, isEnabled: canUndo),
        KeyboardToolGroupItem(style: .secondary, representativeTool: BlockKeyboardTool(symbolName: "arrow.uturn.forward") { [weak self] in
            self?.textView.undoManager?.redo()
            self?.setupKeyboardTools()
        }, isEnabled: canRedo)
    ]),
    // Tools for inserting characters into our text view.
    KeyboardToolGroup(items: [
        KeyboardToolGroupItem(representativeTool: InsertTextKeyboardTool(text: "(", textView: textView), tools: [
            InsertTextKeyboardTool(text: "(", textView: textView),
            InsertTextKeyboardTool(text: "{", textView: textView),
            InsertTextKeyboardTool(text: "[", textView: textView),
            InsertTextKeyboardTool(text: "]", textView: textView),
            InsertTextKeyboardTool(text: "}", textView: textView),
            InsertTextKeyboardTool(text: ")", textView: textView)
        ]),
        KeyboardToolGroupItem(representativeTool: InsertTextKeyboardTool(text: ".", textView: textView), tools: [
            InsertTextKeyboardTool(text: ".", textView: textView),
            InsertTextKeyboardTool(text: ",", textView: textView),
            InsertTextKeyboardTool(text: ";", textView: textView),
            InsertTextKeyboardTool(text: "!", textView: textView),
            InsertTextKeyboardTool(text: "&", textView: textView),
            InsertTextKeyboardTool(text: "|", textView: textView)
        ]),
        KeyboardToolGroupItem(representativeTool: InsertTextKeyboardTool(text: "=", textView: textView), tools: [
            InsertTextKeyboardTool(text: "=", textView: textView),
            InsertTextKeyboardTool(text: "+", textView: textView),
            InsertTextKeyboardTool(text: "-", textView: textView),
            InsertTextKeyboardTool(text: "/", textView: textView),
            InsertTextKeyboardTool(text: "*", textView: textView),
            InsertTextKeyboardTool(text: "<", textView: textView),
            InsertTextKeyboardTool(text: ">", textView: textView)
        ]),
        KeyboardToolGroupItem(representativeTool: InsertTextKeyboardTool(text: "#", textView: textView), tools: [
            InsertTextKeyboardTool(text: "#", textView: textView),
            InsertTextKeyboardTool(text: "\"", textView: textView),
            InsertTextKeyboardTool(text: "'", textView: textView),
            InsertTextKeyboardTool(text: "$", textView: textView),
            InsertTextKeyboardTool(text: "\\", textView: textView),
            InsertTextKeyboardTool(text: "@", textView: textView),
            InsertTextKeyboardTool(text: "%", textView: textView),
            InsertTextKeyboardTool(text: "~", textView: textView)
        ])
    ]),
    KeyboardToolGroup(items: [
        // Tool to present the find navigator.
        KeyboardToolGroupItem(style: .secondary, representativeTool: BlockKeyboardTool(symbolName: "magnifyingglass") { [weak self] in
            self?.textView.findInteraction?.presentFindNavigator(showingReplace: false)
        }),
        // Tool to dismiss the keyboard.
        KeyboardToolGroupItem(style: .secondary, representativeTool: BlockKeyboardTool(symbolName: "keyboard.chevron.compact.down") { [weak self] in
            self?.textView.resignFirstResponder()
        })
    ])
]
You might also like...
Allows users to pull in new song releases from their favorite artists and provides users with important metrics like their top tracks, top artists, and recently played tracks, queryable by time range.

Spotify Radar Spotify Radar is an iOS application that allows users to pull in new song releases from their favorite artists and provides users with i

SwiftUI views that arrange their children in a Pinterest-like layout
SwiftUI views that arrange their children in a Pinterest-like layout

SwiftUI Masonry SwiftUI views that arrange their children in a Pinterest-like layout. HMasonry A view that arranges its children in a horizontal mason

How to build and sign your iOS application using Azure DevOps

How to build and sign your iOS application using Azure DevOps Sample source code

An iOS app that automatically capitalizes the title of your essay. Supports MLA, APA, and Chicago styles.
An iOS app that automatically capitalizes the title of your essay. Supports MLA, APA, and Chicago styles.

Title Capitalizr for iOS An iOS app that automatically capitalizes the title of your essay. Supports MLA, APA, AP, and Chicago styles. "You probably w

Registre-aqui - Mobile Application that displays infrastructure issues that your city may have
Registre-aqui - Mobile Application that displays infrastructure issues that your city may have

Registre Aqui About | Features | Technologies | Requirements About Mobile Applic

Snitch - A handy library to access useful information about your application from the Home Screen
Snitch - A handy library to access useful information about your application from the Home Screen

Snitch Access your app's useful information from Home Screen Table of Contents I

PizzInfo - A SwiftUI based app to know a bit bout your favourite pizzas

PizzInfo Downloading all the playgrounds Unless otherwise indicated, all playgro

CodeEdit App for macOS – Elevate your code editing experience. Open source, free forever.
CodeEdit App for macOS – Elevate your code editing experience. Open source, free forever.

CodeEdit for macOS CodeEdit is a code editor built by the community, for the community, written entirely and unapologetically for macOS. Features incl

An app that displays tracks and albums of your favorite artist.
An app that displays tracks and albums of your favorite artist.

Tunely Description A basic iOS app written in Swift that displays tracks from the iTunes API. There are two tabs. The first shows a list of tracks. Cl

Comments
  • Handle touch cancellation / touch up away from button correctly

    Handle touch cancellation / touch up away from button correctly

    Hi @simonbs, nice library. Very useful to save reimplementing this.

    I noticed you weren't able to cancel a button press by moving away from the button (as also mentioned in #1 )

    This is a simple patch to only run the representativeTool action if 'touchUpInside' was fired (rather than outside as well). It should not affect behaviour of the sub-tools.

    opened by apptekstudios 0
  • Improvement: allow

    Improvement: allow "horizontal swipe" to switch action

    Hey, super nice project!

    Started using it, and I have an improvement request that could make the toolbar feel a bit more native: When you let the finger down on the keyboard, you can select keys. If you try the same thing on KeyboardToolbar, only the first one pressed stay active ; and will trigger the action.

    Here a video that kinda show the behavior I just described

    https://user-images.githubusercontent.com/8696821/176039765-317ba7a8-a4d9-4c58-8fc7-a532324f252d.mov

    Recommendations:

    • Make buttons "touchUpInside" ; allowing users to cancel when they swipe away
    • Allow switching buttons when we enter the context of another one.

    I know that along with the "submenu" it might not be an easy behavior to implement, but you know, that's the kind of attention to detail my ADHD personality stop on when it sees it !

    opened by Dean151 1
Releases(0.1.1)
Owner
Simon Støvring
I tinker with iOS automation and poke at private APIs. Working on Runestone, Scriptable, Jayson, and Data Jar.
Simon Støvring
Arrange views in your app’s interface using layout tools that SwiftUI provides.

Composing custom layouts with SwiftUI Arrange views in your app's interface using layout tools that SwiftUI provides. Overview This sample app demonst

Apple Sample Code 0 Jun 9, 2022
A Set of Tools To Extend UIKit (Classic iOS Framework)

RVS_UIKit_Toolbox A set of basic UIKit tools, for Swift iOS app development. Overview This package offers a few extensions of standard UIKit classes,

The Great Rift Valley Software Company 2 Jul 8, 2022
Reframing SwiftUI Views. A collection of tools to help with layout.

Overview A Swift Package with a collection of SwiftUI framing views and tools to help with layout. Size readers like WidthReader, HeightReader, and on

Ryan Lintott 84 Dec 16, 2022
Make your notification banners smaller and add some color to them

Liddell Liddell notification banners Installation Add this repository to your Package Manager: https://repo.litten.love Install Liddell Compiling Depe

alexandra 34 Dec 22, 2022
IOS-App4 - Core Data add new data and update data

iOS-App4 Core Data add new data and update data.

null 0 Jan 8, 2022
UIViews that update themselves when your data changes, like React.

StateView is a UIView substitute that automatically updates itself when data changes. Contents: Overview What's it like? Sample apps How does it work?

Sahand Nayebaziz 491 Sep 9, 2022
LoadingButtton - Add button extendded from LoadingButton in the view and make it center horizontally

LoadingButtton Usage/Examples Add button extendded from LoadingButton in the vie

Alireza 1 Jan 8, 2022
iOS constraint maker you always wanted. Write constraints like sentences in English. Simple

YeahLayout iOS constraint maker you always wanted. Write constraints like sentences in English. Simple. Intuitive. No frightening abstractions. One fi

Андрей Соловьев 1 Jan 10, 2022
This library allows you to make any UIView tap-able like a UIButton.

UIView-TapListnerCallback Example To run the example project, clone the repo, and run pod install from the Example directory first. Installation UIVie

wajeehulhassan 8 May 13, 2022
A mental health app designed to help users track their emotions with short, tweet-like journals.

Objective The purpose of this project is to create a mental health app where users will input a short journal each day that is no longer than a tweet

Isha Mahadalkar 0 Dec 25, 2021