Comments (9)
Hello @cesarmtz93
We use input accessory views in JT app with this control without any problems.
Maybe you can try to return your toolbar view in the view controller:
class YourViewController: UIViewController {
// other stuff
override var inputAccessoryView: UIView? {
return toolbar
}
from animatedtextinput.
Hi @victorBaro
this is the error that it´s throwing me
Cannot assign to property: 'inputAccessoryView' is a get-only property
and here´s my code
let doneToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
doneToolbar.barStyle = UIBarStyle.default
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.done, target: self, action: #selector(animatedTextInputShouldReturn))
var items = [UIBarButtonItem]()
items.append(flexSpace)
items.append(done)
doneToolbar.items = items
doneToolbar.sizeToFit()
textInputs[2].placeHolderText = NSLocalizedString("Price", comment: "")
textInputs[2].style = CustomTextInputStyleFullWhite() as AnimatedTextInputStyle
textInputs[2].delegate = self
textInputs[2].tag = 2
textInputs[2].type = .numeric
textInputs[2].inputAccessoryView = doneToolbar
I don't really know what´s going on, but I do really appreciate the help!
from animatedtextinput.
Yes, you won't be able to set textInput's inputAccessoryView
. You have to override your UIViewController
property.
class YourViewController: UIViewController {
override var inputAccessoryView: UIView? {
let doneToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
doneToolbar.barStyle = UIBarStyle.default
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.done, target: self, action: #selector(animatedTextInputShouldReturn))
let items = [flexSpace, done]
doneToolbar.items = items
return doneToolbar
}
func viewDidLoad() {
textInputs[2].placeHolderText = NSLocalizedString("Price", comment: "")
textInputs[2].style = CustomTextInputStyleFullWhite() as AnimatedTextInputStyle
textInputs[2].delegate = self
textInputs[2].tag = 2
textInputs[2].type = .numeric
// DO NOT SET THIS DIRECTLY
// textInputs[2].inputAccessoryView = doneToolbar
}
}
from animatedtextinput.
seem a good solution but now in the delegate method i cannot get the tag number
since mi initial setup is
textInputs[0].placeHolderText = NSLocalizedString("Product Name", comment: "")
textInputs[0].style = CustomTextInputStyleFullWhite() as AnimatedTextInputStyle
textInputs[0].delegate = self
textInputs[0].tag = 0
textInputs[1].placeHolderText = NSLocalizedString("Category", comment: "")
textInputs[1].type = .selection
textInputs[1].style = CustomTextInputStyleFullWhite() as AnimatedTextInputStyle
textInputs[1].delegate = self
textInputs[1].tapAction = { [weak self] in
guard let strongself = self else { return }
strongself.createPickerView()
self?.view.endEditing(true)
self?.scrollView.setContentOffset(CGPoint(x: 0,y: 0), animated: true)
}
textInputs[2].placeHolderText = NSLocalizedString("Price", comment: "")
textInputs[2].style = CustomTextInputStyleFullWhite() as AnimatedTextInputStyle
textInputs[2].delegate = self
textInputs[2].tag = 1
textInputs[2].type = .numeric
func animatedTextInputShouldReturn(animatedTextInput: AnimatedTextInput) -> Bool {
let view = self.view.viewWithTag(animatedTextInput.tag + 1)
if view == nil {
//_ = animatedTextInput.resignFirstResponder()
self.view.endEditing(true)
scrollView.setContentOffset(CGPoint(x: 0,y: 0), animated: true)
} else {
view?.becomeFirstResponder()
}
return true
}
noticed i have already implemented the override of the inputAccessoryView
since the toolbar it's sending it self i'm guessing that self is the tool bar not the text input itself
from animatedtextinput.
I don't understand the problem. What do you mean by since the toolbar it's sending it self i'm guessing that self is the tool bar not the text input itself
? self
is your view controller.
Also, what are you trying to achieve? Move from one textInput to the next? If that's what you are trying to do, yo don't need to use tags. You could do something like...
private var currentInputIndex: Int = 0
func viewDidLoad() {
textInputs[0].placeHolderText = NSLocalizedString("Product Name", comment: "")
textInputs[0].style = CustomTextInputStyleFullWhite() as AnimatedTextInputStyle
textInputs[0].delegate = self
textInputs[0].tag = 0
textInputs[1].placeHolderText = NSLocalizedString("Category", comment: "")
textInputs[1].type = .selection
textInputs[1].style = CustomTextInputStyleFullWhite() as AnimatedTextInputStyle
textInputs[1].delegate = self
textInputs[1].tapAction = { [weak self] in
guard let strongself = self else { return }
strongself.createPickerView()
self?.view.endEditing(true)
self?.scrollView.setContentOffset(CGPoint(x: 0,y: 0), animated: true)
}
textInputs[2].placeHolderText = NSLocalizedString("Price", comment: "")
textInputs[2].style = CustomTextInputStyleFullWhite() as AnimatedTextInputStyle
textInputs[2].delegate = self
textInputs[2].tag = 1
textInputs[2].type = .numeric
}
func animatedTextInputDidBeginEditing(animatedTextInput: AnimatedTextInput) {
guard let index = textInputs.index(of: animatedTextInput) else { return }
currentInputIndex = index
}
func animatedTextInputShouldReturn(animatedTextInput: AnimatedTextInput) -> Bool {
if currentInputIndex == textInputs.count {
//Last text input
self.view.endEditing(true)
scrollView.setContentOffset(CGPoint(x: 0,y: 0), animated: true)
} else {
textInputs[index]?.becomeFirstResponder()
}
return true
}
I am closing this issue. I think it was solved with my previous comment. Reopen if needed.
from animatedtextinput.
@victorBaro thanks for the help! one last question by doing this, the toolbar will get set to all of the textInputs is there a way to only set it to a certain textInput?
from animatedtextinput.
Mmmmm yeah I feel like we should do something about that. I am about to generate a new release, I will try to look into that. I think we should add inputView
and inputAccessoryView
to the textinput.
In the meantime, have you tried to return different views on the inputAccessoryView
based on the current first responder?
from animatedtextinput.
@victorBaro yeah actually i ended up doing that, but i just wanted to highlight that it would add the toolbar to all the fields, like you said it´s just something that might want to check out for the next release,
also one quick question, will you be adding other text inputs in the new release e.g. phonePad maybe?
Thanks for the help!
from animatedtextinput.
Also, there is a numericType
. You can create more keyboards (phonePad) if needed.
from animatedtextinput.
Related Issues (20)
- Underlyne style HOT 1
- How can i limit height for multiline HOT 4
- LineHeight only applies correctly to the first input in ViewController
- 'weak' should not be applied to a property declaration in a protocol and will be disallowed in future versions HOT 1
- RxSwift and AnimatedTextInput HOT 1
- how set textContentType? eg: oneTimeCode
- how to sent custom placeholder font HOT 1
- Label cut off bottom HOT 1
- Secured Entry HOT 1
- compile errors when using with Swift 3
- Setting first height bigger
- Numeric field
- how to do deleteBackward() and func textRange(from fromPosition: UITextPosition, to toPosition: UITextPosition) -> UITextRange?
- Add SPM Support
- I can't see it when I put the emoji as a value in the placeholder HOT 2
- iOS 13 dark mode support is not available
- Performance issue during text input HOT 1
- How to focus in AnimatedTextInput? HOT 1
- How to change text format? HOT 1
- After backspace, the letter after capital letter makes keyboard uppercase HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from animatedtextinput.