Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

How can i set input view to AnimatedTextInput ? I want to add picker view as input view to it. #39

Closed
mukulm24 opened this issue Mar 20, 2017 · 4 comments

Comments

@mukulm24
Copy link

mukulm24 commented Mar 20, 2017

inputView is get-only property.

@cesarmtz93
Copy link

@mukulm24 did you manage to do this?

@jorgerebolloj
Copy link

jorgerebolloj commented Apr 7, 2017

@victorBaro Any clue for me being able to set inputView in AnimatedTextInput? Like UIPickerView or UIDatePicker

@victorBaro
Copy link
Contributor

As I mentioned here, I will add support for inputView and accessoryView. I will try to add it very soon.

Currently, you can override your ViewController's inputView and return your date picker, or you can create your own textView/textField, conform to TextInput protocol and pass your date picker.

Something like this:

// For a more in-depth example, take a look at `AnimatedTextView` or `AnimatedTextField`. These classes are now internal, but they will be public in the next release.
class MyTextView: UITextView, TextInput {

    var view: UIView {
        return self
    }

    var currentText: String? {
        get { return text }
        set { self.text = newValue }
    }

    var currentSelectedTextRange: UITextRange? {
        get { return self.selectedTextRange }
        set { self.selectedTextRange = newValue }
    }

    var textAttributes: [String: Any]? {
        didSet {
            guard let attributes = textAttributes else { return }
            typingAttributes = attributes
        }
    }

    weak var textInputDelegate: TextInputDelegate?

    var currentBeginningOfDocument: UITextPosition? {
        return self.beginningOfDocument
    }

    func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType) {
        returnKeyType = newReturnKeyType
    }

    func currentPosition(from: UITextPosition, offset: Int) -> UITextPosition? {
        return position(from: from, offset: offset)
    }
}


class ViewController: UIViewController {

    @IBOutlet var textInput: AnimatedTextInput!

    override func viewDidLoad() {
        textInput.placeHolderText = "Date picker"
        let myTextInput = MyTextView()
        //Configure and assign your input view
        myTextInput.inputView = UIDatePicker()
        textInputs[2].type = .generic(textInput: myTextInput)
    }
}

@victorBaro
Copy link
Contributor

@mukulm24 @cesarmtz93 @jorgerebolloj
This PR has just been approved and merged in master. I will be generating a new version very soon with the new changes.

#49 (review)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants