• Stars
    star
    103
  • Rank 322,419 (Top 7 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⌨️ The most simple custom keyboard generator for iOS ever!

KeyboardLayoutEngine

Version License

⌨️ The most simple custom keyboard generator for iOS ever!

alt tag

KeyboardLayoutEngine is all about laying out keyboard buttons dynamically in a rectangle with a custom style easily. For the sake of flexibility, KeyboardLayoutEngine provides:

  • KeyboardLayout: For laying out rows with custom paddings, colors.
  • KeyboardRow: For laying out buttons or another set of KeyboardRow's inside.
  • KeyboardButton: For rendering buttons in rows. Also provides flexible width, type and other very useful API's.
  • They are also UIViews and handles their layout in their layoutSubviews function.
  • They are faster than autolayout yet they can adopt perfectly any CGFrame you want apply a keyboard layout.
  • That means they are play very well with orientation changes. (Layout for size class and/or orientation support is on the way.)
  • KeyboardLayoutStyle, KeyboardRowStyle and KeyboardButtonStyle structs handles pretty much everything about styling.
  • KeyboardLayoutDelegate for inform about button presses.
  • Also CustomKeyboard provided out of box, a good start point for figuring out how it works other than being of fully functional original keyboard.

Install

CocoaPods

use_frameworks!
# Target Keyboard
pod 'KeyboardLayoutEngine'

Usage

  • Describe your keyboard with custom styles, rows and buttons with either text or image in it.
  • Checkout the CustomKeyboardLayout for detailed usage.
let keyboardLayout = KeyboardLayout(
  style: CustomKeyboardLayoutStyle,
  rows: [
    KeyboardRow(
      style: CustomKeyboardRowStyle,
      characters: [
        KeyboardButton(type: .Key("Q"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("W"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("E"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("R"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("T"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("Y"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("U"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("I"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("O"), style: CustomKeyboardKeyButtonStyle),
        KeyboardButton(type: .Key("P"), style: CustomKeyboardKeyButtonStyle),
      ]
    )
  ]
)

override func viewDidLoad() {
	super.viewDidLoad()
	view.addSubview(keyboardLayout)
}

override func viewDidLayoutSubviews() {
	super.viewDidLayoutSubviews()
	keyboardLayout.setNeedsLayout()
}

KeyboardLayoutDelegate

  • Implement KeyboardLayoutDelegate for get information about the button presses.
@objc public protocol KeyboardLayoutDelegate {
  // Key Press Events
  optional func keyboardLayout(keyboardLayout: KeyboardLayout, didKeyPressStart keyboardButton: KeyboardButton)
  optional func keyboardLayout(keyboardLayout: KeyboardLayout, didKeyPressEnd keyboardButton: KeyboardButton)
  optional func keyboardLayout(keyboardLayout: KeyboardLayout, didDraggedIn fromKeyboardButton: KeyboardButton, toKeyboardButton: KeyboardButton)
  // Touch Events
  optional func keyboardLayout(keyboardLayout: KeyboardLayout, didTouchesBegin touches: Set<UITouch>)
  optional func keyboardLayout(keyboardLayout: KeyboardLayout, didTouchesMove touches: Set<UITouch>)
  optional func keyboardLayout(keyboardLayout: KeyboardLayout, didTouchesEnd touches: Set<UITouch>?)
  optional func keyboardLayout(keyboardLayout: KeyboardLayout, didTouchesCancel touches: Set<UITouch>?)
}

KeyboardButtonWidth

public enum KeyboardButtonWidth {
  case Dynamic
  case Static(width: CGFloat)
  case Relative(percent: CGFloat)
}
  • Laying out buttons in rows are important. Since rows can their child rows, calculating right sizes for buttons and rows done by button types.
  • If you leave .Dynamic which is default by the way, every button in a row, it will calculate their width by KeyboardRowStyle.buttonPadding and total width of row and figure out equal widths with equal buttonPaddings.
  • Static will be static width obviusly.
  • Relative is an interesting one, which takes a value between [0, 1], fills percent of parent row, smartly calculated.

KeyboardButtonType

public enum KeyboardButtonType {
  case Key(String)
  case Text(String)
  case Image(UIImage?)
}
  • A button can be Key, Text or Image.
  • Key case might be useful for textDocumentProxy.insertTextoperation.
  • Text case might be useful for buttons like "space", "return", "ABC", "123" or any string include emojis.
  • Image case might be useful for buttons like "shift", "backspace", "switch keyboard" etc.

Styling

  • Every style struct has their default values in taste of original keyboard.
  • If you dont assign a value in init function of a style struct, it will be loaded with its default value.

KeyboardLayoutStyle

Definition:

public struct KeyboardLayoutStyle {
  public var topPadding: CGFloat
  public var bottomPadding: CGFloat
  public var rowPadding: CGFloat
  public var backgroundColor: UIColor
}

Example:

let CustomKeyboardLayoutStyle = KeyboardLayoutStyle(
  topPadding: 10,
  bottomPadding: 5,
  rowPadding: 13,
  backgroundColor: UIColor(red: 208.0/255.0, green: 213.0/255.0, blue: 219.0/255.0, alpha: 1))

KeyboardRowStyle

Definition:

public struct KeyboardRowStyle {
  public var leadingPadding: CGFloat
  public var trailingPadding: CGFloat
  public var buttonsPadding: CGFloat
}

Example:

let CustomKeyboardRowStyle = KeyboardRowStyle(
  leadingPadding: 5,
  trailingPadding: 5,
  buttonsPadding: 6)

KeyboardButtonStyle

Definition:

public struct KeyboardButtonStyle {
  public var backgroundColor: UIColor
  public var cornerRadius: CGFloat

  // Border
  public var borderColor: UIColor
  public var borderWidth: CGFloat

  // Shadow
  public var shadowColor: UIColor
  public var shadowOpacity: Float
  public var shadowOffset: CGSize
  public var shadowRadius: CGFloat
  public var shadowPath: UIBezierPath?

  // Text
  public var textColor: UIColor
  public var font: UIFont

  // Image
  public var imageSize: CGFloat?

  // Popup
  public var showsPopup: Bool
  public var popupWidthMultiplier: CGFloat
  public var popupHeightMultiplier: CGFloat
}

Example:

let CustomKeyboardDarkImageButtonStyle = KeyboardButtonStyle(
  backgroundColor: UIColor(red: 180.0/255.0, green: 188.0/255.0, blue: 201.0/255.0, alpha: 1),
  imageSize: 18,
  showsPopup: false)

CustomKeyboard

Default iOS Keyboard implementation with KeyboardLayoutEngine.

  • Shift toggle mechanism
  • Backspace mechanism
  • Key button popups
  • textDocumentProxy integrations with CustomKeyboardDelegate
  • Ridiculusly easy implementation in KeyboardViewController
  • Change default styles before initialize it and you have your fully functional customized standard English QWERTY keyboard!
override func viewDidLoad() {
    super.viewDidLoad()
    CustomKeyboardLayoutStyle.backgroundColor = UIColor.redColor()
    CustomKeyboardRowStyle.buttonsPadding = 5
    customKeyboard = CustomKeyboard()
    customKeyboard.delegate = self
    view.addSubview(customKeyboard)
}

CustomKeyboard styles

  • CustomKeyboardLayoutStyle: KeyboardLayoutStyle
  • CustomKeyboardRowStyle: KeyboardRowStyle
  • CustomKeyboardSecondRowStyle: KeyboardRowStyle
  • CustomKeyboardChildRowStyle: KeyboardRowStyle
  • CustomKeyboardSpaceButtonStyle: KeyboardButtonStyle
  • CustomKeyboardBackspaceButtonStyle: KeyboardButtonStyle
  • CustomKeyboardShiftButtonStyle: KeyboardButtonStyle
  • CustomKeyboardGlobeButtonStyle: KeyboardButtonStyle
  • CustomKeyboardReturnButtonStyle: KeyboardButtonStyle
  • CustomKeyboardNumbersButtonStyle: KeyboardButtonStyle
  • CustomKeyboardKeyButtonStyle: KeyboardButtonStyle

CustomKeyboardDelegate

  • Provides information about key and special button presses.
@objc public protocol CustomKeyboardDelegate {
optional func customKeyboard(customKeyboard: CustomKeyboard, keyboardButtonPressed keyboardButton: KeyboardButton)
optional func customKeyboard(customKeyboard: CustomKeyboard, keyButtonPressed key: String)
optional func customKeyboardSpaceButtonPressed(customKeyboard: CustomKeyboard)
optional func customKeyboardBackspaceButtonPressed(customKeyboard: CustomKeyboard)
optional func customKeyboardGlobeButtonPressed(customKeyboard: CustomKeyboard)
optional func customKeyboardReturnButtonPressed(customKeyboard: CustomKeyboard)
}

More Repositories

1

MusicTheory

Universal music theory library for iOS, iPadOS, macOS, tvOS and watchOS in Swift
Swift
398
star
2

CategorySliderView

slider view for choosing categories. add any UIView type as category item view. Fully customisable
Objective-C
352
star
3

PullToRefreshCoreText

PullToRefresh extension for all UIScrollView type classes with animated text drawing style
Objective-C
313
star
4

ReorderableGridView-Swift

reorderable grid view solution implemented with swift. its UIScrollView subclass, its not a collection view layout.
Swift
279
star
5

SlidingContainerViewController

An android scrollable tab bar style container view controller
Swift
219
star
6

MaterialCardView

Create material design cards quick and easy
Swift
219
star
7

StrechyParallaxScrollView

uiscrollview with strechy and parallax top view
Objective-C
207
star
8

TransitionManager

Painless custom transitioning. Easy extend, easy setup, just focus on animations.
Swift
205
star
9

BubbleControl-Swift

a bubble control highly inspired from facebook chat heads. written in swift
Swift
178
star
10

ImageFreeCut

A UIView subclass lets you draw a path over an image and crops that part.
Swift
174
star
11

GiFHUD

progress hud for displaying only animated gif images. no labels (for now)
Objective-C
159
star
12

MIDITimeTableView

Customisable and editable time table grid for showing midi or audio related data with a measure.
Swift
120
star
13

DroppyScrollView

Vertical scroll view with abilty to inserting subviews top or any index with stylish dropping animations
Objective-C
118
star
14

ChordDetector

A tiny menu bar app detecting the chords of the songs you are listening on iTunes or Spotify.
Swift
75
star
15

MIDIPianoRollView

Customisable UIScrollView subclass for rendering/editing MIDI notes on a piano roll view.
Swift
74
star
16

GiFHUD-Swift

progress hud for displaying only animated gif images implemented with swift
Swift
69
star
17

Fretboard

Customisable guitar fretboard view for iOS, tvOS and macOS with CoreGraphics
Swift
55
star
18

LiveKnob

Yet another knob for iOS but with IBDesignable and Ableton Live style.
Swift
52
star
19

JSONTableView

Expandable JSON data viewer
Swift
45
star
20

CircleOfFifths

Fully customisable IBDesignable circle of fifths implementation in swift.
Swift
44
star
21

CEMKit-Swift

UIKit & Foundation toolbelt for quick prototyping and rapid development
Swift
40
star
22

SizeClasser

Device specific UITraitCollection helper with split view detection for iOS.
Ruby
35
star
23

MIDIEventKit

MIDI data structures for Swift. Send MIDI events in human language.
Swift
30
star
24

YSTypingAnimation

customisable "is typing" animation view written in swift.
Swift
29
star
25

AUSequencer

(WIP) MIDI Sequencer Audio Unit
Objective-C++
26
star
26

TVOSPicker

A sweet horizontal picker view controller for tvOS.
Swift
25
star
27

PercentCalculator

A menu bar application that calculates parcents.
Swift
24
star
28

MIDISequencerAUv3

A great start point for making AUv3 MIDI sequencer apps.
Objective-C
24
star
29

GlowingView

A UIView extension adds customisable glow effect based on CALayer shadows.
Ruby
23
star
30

LiveFader

@IBDesignable Horizontal or vertical UIControl subclass that can start from bottom or middle of the control.
Swift
22
star
31

BlockTableView-Swift

single line UITableView creation in Swift with power of the closures
Swift
21
star
32

AIBud

An experimental CreateML project for predicting playing musical key and scale in realtime
Swift
19
star
33

ContinuesTouchCollectionView

A collection view subview for handling multiple continues touches on cells.
Swift
17
star
34

MarchingLayer

Randomly fills layer with sprites and move them in any direction and speed you want.
Swift
17
star
35

CirucularLock

fully custumisable lock control with block based callbacks.
Objective-C
16
star
36

DragMenuPicker

A custom picker lets you pick an option from its auto scrolling menu without lifting your finger up.
Swift
14
star
37

TempoStepper

Fully customisable stepper with auto stepping.
Swift
14
star
38

YSTutorialViewController

Create flat design tutorial pages quickly. It can read page data from json file, no coding required for pages ! Fully customisable.
Objective-C
13
star
39

3DTouchHelper

Easy to use continuous 3D touch gesture recognizer.
Swift
12
star
40

IBDesignableArrowView

Create IBDesignable arrow views in your storyboard!
Swift
12
star
41

DeserializableSwiftGenerator

JSONHelper or ObjectMapper deserializable swift class generator
Swift
12
star
42

MusicTheoryCpp

C++ music theory library
C++
11
star
43

RBEditorViewController

RhythmBud's Editor Code
Swift
10
star
44

Flick

A smart swipe gesture with direction, duration, velocity and force properties.
Swift
9
star
45

LaunchpadKit

Swift API for Novation Launchpad
Swift
9
star
46

CenterTextLayer

Universal CATextLayer subclass that centers its text vertically.
Ruby
9
star
47

ALKit

Easy to use AutoLayout wrapper around NSLayoutConstraints.
Swift
7
star
48

MothersDiceGame

Random synth patch generator iOS app
Swift
7
star
49

BezierCurveEditor

UIBezierPath editor view for iOS.
Swift
6
star
50

ColorPalette

A color palette grid view for iOS.
Swift
6
star
51

StringToPath

String extension for returning UIBezierPath of the string in a font of your choice, using Core Text
Ruby
6
star
52

MotionImageView

An image view lets you move its image with gyro
Swift
6
star
53

WatchActivityIndicator

⌚️ Apple Watch WKInterfaceImage and WKInterfaceGroup extension for showing activity indicators on them quickly.
Swift
6
star
54

CEMKit

handy library for no-xibbers
Objective-C
5
star
55

AirDrawerMenuViewController

legendary airbnb drawer menu in swift
Swift
5
star
56

DroppyMenuController

A swift dropping menu controller.
Swift
5
star
57

DroppyExpandingSectionView

Instead of using UITableView or UICollectionView use this for expand/collapse behaviour. Implementation higly mimics UICollectionView. Its more easy because just waits the headers and their expanding items which are any UIView type object
Objective-C
5
star
58

RECButton

An @IBDesignable record (REC) button for iOS
Ruby
4
star
59

StatusBarTranslator

osx status bar app for translating english to french or vice versa. implemented using yandex translation api in swift
Swift
4
star
60

SlotPickerView

Picker view with multiple ranges for iOS
Swift
3
star
61

OptionButton

IBDesignable option button that have vertical stacked title and option labels for iOS and tvOS.
Ruby
3
star
62

EmojiKeyboard

EmojiKeyboard provides a complete view controller with EmojiCollectionView, EmojiCollectionViewCell and EmojiCollectionViewHeader in style of Apple Emoji Keyboard.
Swift
3
star
63

CurlUI

A tiny mac tool for testing your POST/GET requests.
Swift
2
star
64

Shadow

A simple object for adding/removing shadows from your CALayers or UIViews.
Swift
2
star
65

RadyoEksen

osx status bar application for radio eksen 96.2 FM, Istanbul
Swift
2
star
66

DurationProgressBar

UIView based progress bar that shows the duration in seconds
Swift
2
star
67

Blogs

Repo that host my blog posts about iOS and Swift
2
star
68

ImageSequance

Universal image sequance animation library for iOS, tvOS, macOS and watchOS.
Ruby
2
star
69

XYPad

A quick and easy xy-pad control for iOS
Swift
2
star
70

RowyGenerator

an experimental functional UIView generator in swift
Swift
1
star
71

YSCards

under development
Swift
1
star
72

CocosCharacterGenerator

Cocos2d Character Generator Cocoa App
Objective-C
1
star
73

IBDesignableProgressBar

Create flat progress bars directly from storyboard.
Swift
1
star
74

Hoopscore

Free and open source app for keeping score of your basketball practices
Swift
1
star
75

AutoScroller

Display custom "scroll to top" or "scroll to bottom" views in all UIScrollView instances while they are scrolling
Swift
1
star
76

SoundcloudFavoritesDownloader

download your favorites in soundcloud. or listen. or both
JavaScript
1
star
77

cucumber-step-generator

Atom package for generating cucumber step files from feature files
CoffeeScript
1
star
78

dotfiles

zsh, bash, vim and Terminal.app settings
Shell
1
star
79

ColourLoversExtensionGenerator

a status bar app for generating UIColor extension class form colourlovers.com palettes
Objective-C
1
star
80

DictUtils

Adds bunch of extensions and operators that would make working with Dicitonaries easier.
Swift
1
star
81

DSLSwitch

iOS app for controlling Marshall DSL amps
Swift
1
star
82

ProtocolOrientedViewModel

Create universal view's with different layouts for each platform and share the view logic between them.
Swift
1
star