Coder Social home page Coder Social logo

tmkeyboardmanager's Introduction

TMKeyboardManager


Features

  • Automatic frame for Controllers with keyboard functionality
  • Easiest access to the keyboard behaviour
  • Autohide keyboard on background tap
  • Easy work with multiple InputFields
  • UIPicker/UIDatePicker as keyboard
  • Done and Next+Done toolbar for keyboard

Requirements

  • iOS 14.0+
  • Xcode 13

Installation

Swift Package Manager

Instructions for Swift Package Manager support can be found at SwiftPackageManager Markdown file.

Usage example

Automatic frame for Controllers with keyboard functionality

import UIKit
import TMKeyboardManager

class ViewController: UIViewController, TMKeyboardDelegate {
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.initKeyboard()
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        self.deinitKeyboard()
    }
}

Easiest access to the keyboard behaviour

import UIKit
import TMKeyboardManager

class ViewController: UIViewController, TMKeyboardDelegate {
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.initKeyboard()

    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        self.deinitKeyboard()
    }

    // MARK: - TMKeyboardDelegate
    func keyboardWillShow() {
        print("keyboardWillShow")
    }

    func keyboardWillHide() {
        print("keyboardWillHide")
    }

    func keyboardDidShow() {
        print("keyboardDidShow")
    }

    func keyboardDidHide() {
        print("keyboardDidHide")
    }
}

Easy work with multiple InputFields

Inherit your UITextFielf with TMTextField

Use next functions to add toolbars

firstTextField.delegate = self
secondTextField.delegate = self
        
firstTextField.setNextDoneToolbar()
secondTextField.setDoneToolbar()

And provide shouldReturn Delegate function from UITextFieldDelegate

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    self.focusOnNextPesponder(textField)
}

Full Implementation

import UIKit
import TMKeyboardManager

class DelegateViewController: UIViewController, UITextFieldDelegate {
    @IBOutlet weak var firstTextField: TMTextField!
    @IBOutlet weak var secondTextField: TMTextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        firstTextField.delegate = self
        secondTextField.delegate = self

        firstTextField.setNextDoneToolbar()
        secondTextField.setDoneToolbar()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.initKeyboard()
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        self.deinitKeyboard()
    }

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        self.focusOnNextPesponder(textField)
    }
}

Picker Keyboard

  1. Inherit your UITextField from TMTextField
@IBOutlet weak var datePickerTextField: TMTextField!
  1. Add setPickerKeyboard with UIPickerViewDelegate as Delegate
override func viewDidLoad() {
    super.viewDidLoad()
    pickerTextField.setPickerKeyboard(self)
}
  1. And implement UIPickerViewDelegate as usual
extension PickerViewController: UIPickerViewDelegate, UIPickerViewDataSource {
    func numberOfComponents(in pickerView: UIPickerView) -> Int {  }
    
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {  }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {  }
}

DatePicker Keyboard

  1. Inherit your UITextField from TMTextField
@IBOutlet weak var datePickerTextField: TMTextField!
  1. Add setDatePickerKeyboard with UIPickerViewDelegate as Delegate and selector (See Step 3)
override func viewDidLoad() {
    super.viewDidLoad()
    datePickerTextField.setDatePickerKeyboard(self, selector: #selector(dateDidChange(sender:)))
}
  1. Add selector with UIDatePicker as Sender
@objc func dateDidChange(sender: UIDatePicker) {
    print(sender.date.description)
}

Customisation

Use TMKeyboardConfig flags to convigure available options:

  • tintColor
import UIKit
import TMKeyboardManager

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        TMKeyboardConfig.tintColor = .systemMint
        return true
    }
}

License


Package released under the Apache 2.0 license, check the LICENSE file for more info.

tmkeyboardmanager's People

Contributors

rayllienstery avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.