Skip to content

Keyboard makes easy to use inputAccessoryView in UIViewController, UITextView, UITextField and UISearchBar.

License

Notifications You must be signed in to change notification settings

adboco/Keyboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keyboard

Version License Platform Swift Version FOSSA Status

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Xcode 9.0+
  • iOS 8.0+

Installation

Keyboard is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'KeyboardSwift'

Usage

import KeyboardSwift

You can use Keyboard in UIViewController or any UIView with inputAccessoryView (UITextField, UISearchBar, UITextView). Simply call keyboard and configure it with the items you want. An example:

let cancelItem = KeyboardItem.barButton(title: "Cancel", style: .plain) { item in
	// Called when cancel item is tapped
    self.textView.endEditing(true)
}

let countLabel = UILabel()
countLabel.text = "0"
let labelItem = KeyboardItem.custom(view: countLabel)

let doneItem = KeyboardItem.barButton(title: "Done", style: .done) { item in
	// Called when done item is tapped
    self.textView.endEditing(true)
}

textView.keyboard.with(items: cancelItem, .flexibleSpace, labelItem, .flexibleSpace, doneItem)

alt text

KeyboardItem

/// Default bar button item
case barButton(title: String, style: UIBarButtonItemStyle, action: UIBarButtonItemTargetClosure?)

/// System bar button item
case systemBarButton(system: UIBarButtonSystemItem, action: UIBarButtonItemTargetClosure?)

/// Flexible space
case flexibleSpace

/// Fixed space
case fixedSpace(width: CGFloat)

/// Custom view
case custom(view: UIView)

Customize

You can customize the accessoryView calling customize method:

textView.keyboard.customize { (toolbar, items) in
    toolbar.isTranslucent = false
    toolbar.tintColor = .purple
}

Keyboard Events

Only available in UIViewController or subclass:

case willShow
case willHide
case didShow
case didHide

Example:

override func viewDidLoad() {
	super.viewDidLoad()

	// Subscribe
	self.keyboard.subscribe(to: .willShow) { sender in
	    // TODO: something to do when keyboard will be shown
	}

	// ...

	// Unsubscribe
	self.keyboard.unsubscribe()
}

Author

adboco@telefonica.net, Adrián Bouza Correa

License

Keyboard is available under the MIT license. See the LICENSE file for more info.

FOSSA Status

About

Keyboard makes easy to use inputAccessoryView in UIViewController, UITextView, UITextField and UISearchBar.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published