项目作者: kmcgill88

项目描述 :
KMKeys provides a drop-in floating text field and toolbar above your choice of system keyboard
高级语言: Swift
项目地址: git://github.com/kmcgill88/KMKeys-iOS.git
创建时间: 2017-04-18T12:43:27Z
项目社区:https://github.com/kmcgill88/KMKeys-iOS

开源协议:MIT License

下载


KMKeys-iOS

Version
License
Platform

Example

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

Short Syntax

  1. KMKeys.show() { (text:String?) in
  2. self.label.text = text
  3. }

Customized

  1. let keys = KMKeys()
  2. // Change Default speed (0.15)
  3. //
  4. keys.animationSpeed = 0.05
  5. // Customize the text field
  6. //
  7. keys.textField.textAlignment = .center
  8. keys.textField.placeholder = "Placeholder Text Here"
  9. keys.textField.font = UIFont(name: "American Typewriter", size: 16.0)!
  10. keys.textField.placeholderColor = UIColor.init(white: 255/255, alpha: 0.75)
  11. keys.textField.backgroundColor = .brown
  12. keys.textField.textColor = .white
  13. keys.textField.tintColor = .white
  14. keys.textField.keyboardType = .decimalPad
  15. keys.textField.keyboardAppearance = .dark
  16. // Customize the toolbar
  17. //
  18. keys.toolbar.barTintColor = .brown
  19. // KMKeyBarButtonItemType.flexibleSpace, .cancel, .done
  20. // Mostly normal buttons, except can set custom titles
  21. //
  22. let flexibleSpace = KMKeyBarButtonItem.flexibleSpace() //<-- Shortcut helper
  23. let cancelBarButton = KMKeyBarButtonItem(title: "Never Mind", style: .plain, action: .cancel, kmKeys: keys)
  24. let doneBarButton = KMKeyBarButtonItem(title: "Fire!!!", style: .done, action: .done, kmKeys: keys)
  25. // let cancelBarButton = KMKeyBarButtonItem.cancel() //<-- Shortcut helper, if custom name not needed
  26. // let doneBarButton = KMKeyBarButtonItem.done() //<-- Shortcut helper, if custom name not needed
  27. // KMKeyBarButtonItemType.textInput
  28. // When you want a toolbar button's title to append to the textField
  29. //
  30. let plusButton = KMKeyBarButtonItem(title: "+", style: UIBarButtonItemStyle.plain, action: KMKeyBarButtonItemType.textInput, kmKeys: keys)
  31. let minusButton = KMKeyBarButtonItem(title: "-", style: .plain, action: .textInput, kmKeys: keys)
  32. let commaButton = KMKeyBarButtonItem(title: ",", style: .plain, action: .textInput, kmKeys: keys)
  33. // KMKeyBarButtonItemType.action
  34. // When you want a button to do
  35. let actionBarButton = KMKeyBarButtonItem(title: "Custom Action", style: .plain, action: KMKeyBarButtonItemType.action, kmKeys: keys, actionHandler: { (_ kmKeys:KMKeys?) in
  36. // Do your custom logic here, in the actionHandler.
  37. //
  38. if let keys = kmKeys {
  39. keys.textField.text = "KMKeys!!!!"
  40. }
  41. })
  42. let fixedSpace = KMKeyBarButtonItem.fixedSpace() //<-- Shortcut helper, by default size is 2% of window width or 5 if window is nil
  43. keys.setToolbarItems(items: [fixedSpace, cancelBarButton, flexibleSpace, plusButton, commaButton, minusButton, actionBarButton, flexibleSpace, doneBarButton, fixedSpace])
  44. keys.setToolbarItemsTintColor(color: .white)
  45. keys.setToolbarItemsFont(font: UIFont(name: "American Typewriter", size: 16.0)!)
  46. keys.show() { (text:String?) in
  47. self.label.text = text
  48. }

Requirements

  • Swift 4+
  • Xcode 9+

Installation

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

  1. pod "KMKeys"

Author

Kevin McGill, kevin@mcgilldevtech.com

License

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