Latest 1.0.1
Homepage https://github.com/sgr-ksmt/FormChangeable
License MIT Copyright (c) 2016 Suguru Kishimoto
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Platforms ios 8.0
Authors

Language
[Xcode]()
[iOS]()
Build Status
Carthage Compatible
Pod Version

Easy to move from UITextField/UITextView to next UITextField/UITextView written in Swift.

Description

Some ViewController have four forms(text field or text view) like nameTextField, emailTextField, passwordTextField and profileTextView.
When they enter their name in and press ‘Next’ on the keyboard, I want this to automatically move to the next Form.
So, I will implement like below:

class ViewController: UIViewController, UITextFieldDelegate {
    @IBOutlet private weak var nameTextField: UITextField!
    @IBOutlet private weak var mailTextField: UITextField!
    @IBOutlet private weak var passwordTextField: UITextField!
    @IBOutlet private weak var profileTextView: UITextView!

    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        if textField == nameTextField {
            mailTextField.becomeFirstResponder()
        } else if textField == mailTextField {
            passwordTextField.becomeFirstResponder()
        } else if textField == passwordTextField {
            profileTextView.becomeFirstResponder()
        } else {
            return true
        }
        return false
    }
}

or,

class ViewController: UIViewController, UITextFieldDelegate {
    @IBOutlet private weak var nameTextField: UITextField!
    @IBOutlet private weak var mailTextField: UITextField!
    @IBOutlet private weak var passwordTextField: UITextField!
    private var textfields = [UITextField]()

    override func viewDidLoad() {
        super.viewDidLoad()
        textfields += [nameTextField, mailTextField, passwordTextField]
    }

    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        let tag = textField.tag
        let nextIndex = tag + 1
        if nextIndex < textfields.count {
            textfields[nextIndex].becomeFirstResponder()
            return false
        }
        return true
    }
}

…It’s not very good.

Problems
  • Need to check forms. 😞
  • Use tag…😞

They are bother!!!

Solution

FormChangeable can resolve these problems.

Feature

  • Don’t have to check form anymore.
  • Don’t use tag.
  • No complex settings.
  • Can move both UITextFIeld and UITextView
  • Move to next/prev form if next/prev form exists.
    If next/prev form don’t exists, only close keyboard in current form.

Usage

  • [1] setup next/prev form
import FormChangeable

class ViewController: UIViewController {
    @IBOutlet private weak var nameTextField: UITextField!
    @IBOutlet private weak var mailTextField: UITextField!
    @IBOutlet private weak var passwordTextField: UITextField!
    @IBOutlet private weak var profileTextView: UITextView!
    override func viewDidLoad() {
        super.viewDidLoad()
        nameTextField.nextForm = mailTextField
        mailTextField.nextForm = passwordTextField
        passwordTextField.nextForm = profileTextView
    }
}

or,

import FormChangeable

class ViewController: UIViewController {
    @IBOutlet private weak var nameTextField: UITextField!
    @IBOutlet private weak var mailTextField: UITextField!
    @IBOutlet private weak var passwordTextField: UITextField!
    @IBOutlet private weak var profileTextView: UITextView!
    override func viewDidLoad() {
        super.viewDidLoad()
        let forms: [FormChangeable] = [nameTextField, mailTextField, passwordTextField, profileTextView]
        forms.registerNextForm()
    }
}
  • [2] Implement UITextFieldDelegate‘s func textFieldShouldReturn(textField:)
  • [3] Implement UITextViewDelegates func textView(textView:, shouldChangeTextInRange:, replacementText:)
class ViewController: UIViewController, UITextFieldDelegate {
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.changeToNextForm()
        return false
    }

    func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
        if text == "n" {
            textView.changeToNextForm()
            return false
        }
        return true
    }
}

Requirements

  • iOS 8.0+
  • Xcode 7.0+(Swift 2+)

Installation

Carthage

  • Add the following to your Cartfile:
github 'sgr-ksmt/FormChangeable' ~> 1.0
  • Run carthage update
  • Add the framework as described.

    Details: Carthage Readme

CocoaPods

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

pod 'FormChangeable', '~> 1.0'

and run pod install

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.:muscle:

License

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

Latest podspec

{
    "name": "FormChangeable",
    "version": "1.0.1",
    "summary": "Easy to move from UITextField/UITextView to next UITextField/UITextView written in Swift.",
    "homepage": "https://github.com/sgr-ksmt/FormChangeable",
    "authors": {
        "Suguru Kishimoto": "[email protected]"
    },
    "source": {
        "git": "https://github.com/sgr-ksmt/FormChangeable.git",
        "tag": "1.0.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "FormChangeable/**/*.swift",
    "license": {
        "type": "MIT",
        "text": "      Copyright (c) 2016 Suguru Kishimoton      Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:n      The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.n      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.n"
    }
}

Pin It on Pinterest

Share This