Custom UIView with keyboard input? - iphone

I have a custom UILabel subclass for displaying currency values. I only want the user to be able to enter digits and let the view format those digits into a currency value -- like a cash register. This makes UITextField an inappropriate choice for this kind of input.
I've already overridden hitTest: so that the UILabel will return itself -- this is apparently a bug. Also, I've overridden both canBecomeFirstResponder and becomeFirstResponder to return YES. Neither of these methods are being called, though.
I only want to let the user type numbers and use the backspace key. I've implemented UITextInputTraits, but the keyboard does not appear. So, can this be done? And does if so, what am I missing?

I've done something like this. Subclass UITextField, make its text color clear, and stick a label on top of it to display the formatted version.
edit - actually, strictly speaking you shouldn't even need to subclass it. Just implement the delegate method (-textField:shouldChangeCharactersInRange:replacementString:), add the label to the UITextField, and format the label's text however you need to.

OK, I've answered my own question: a UILabel placed on top of the UITextView will also hide the insertion point, but can still become the first responder and get input.
Thanks!

Related

are you able to type into a UILabel

Hi I am wondering if you are able to use the ios keyboard to update a textfield as the user types?
you could get each character as they type through UITextFieldDelegate delegate methods,
Once you get the set of character through delegate method , you could update you UILabel.
If you're talking about UITextField, then yes, naturally, those are meant to be modified by the user and interact with the keyboard just fine. If you're talking about UILabel, then no, the user can't type directly into a label, but as #Jhaliya suggests you could update the label whenever the user changes a text field, text view, or other object that can interact with the keyboard.

Is it possible to change the default InputView in MonoTouch?

I would like to display a different view than the standard keyboard (a picker control, or a date picker, for example) when a text field becomes first responder (i.e. gets focus). This would be really nice, because currently I'm pushing a custom view which contains my picker control onto the navigation stack where the user chooses an option, and then hits an OK or Cancel button.
According to the documentation for UITextField.InputView:
Assigning a custom view to this
property causes that view to be
presented instead.
But, It's read only!!!
Is there a workaround for this? Do I need to implement a custom UITextField control and somehow override the InputView property? Do I need to call some kind of native function? I'd really love not to have to do either of those things... but if I have to, so be it. Thanks in advance!
The documentation is slightly out of date. There is a setter since MonoTouch 3.2.0.
Kevin's answer will work for UIKeyboardType keyboards but as far as I'm aware (I could be wrong) you can't present a custom keyboard this way.
The only way I know how to present a custom keyboard is to override the InputView for the UIViewController you wish to present the input view.
UIView keyboardView;
public override UIView InputAccessoryView {
get
{
// create the view as you'd like here
return keyboardView;
}
}
Wire up the UITextField to handle the appropriate editing event and in the event handler select the KeyboardType you want. If you don't need to dynamically set it then you can just set the property when you create the text field.
UITextField tf;
...
tf.KeyboardType = UIKeyboardType.PhonePad; // whatever kb you want

Focus and zoom in on a UITextField when touched?

How in the world does one get the iPhone view to zoom in on a focused UITextField? I need to tap on a text field that I want to edit, and my view should zoom in to the tapped text field and pull up the keyboard (which it already does), similar to how many Internet text fields gain focus on the iPhone. Is this some type of overlay?
I've been looking everywhere for this solution but maybe I've just got the wrong terminology. Thank you in advance.
Could be a duplicate of this StackOverflow question.
In essence, there are a number of ways, but you have to program this effect manually. A textfield is already an overlay. You can either move it, or scroll the containing view.
Please follow the following steps.
Implement the delegate method for all textfield.connect the outlet of textfield in interface builder basically it's setting the delegate property.then in delegate property you can defined the method whatever you want to implement or wanted to do functionality.
Thanks

Custom Number Pad UIKeyboard

How would I go about creating a custom number pad like what is used in 'Tipulator' and other apps.
I know how you can customize UIKeyboard, but their number pad doesn't look at all like the default number pad. Is it even a UIKeyboard or a separate UIView?
I've been working with keyboards for quite a time. I would say that the easiness of this depends on what your target text input view is. If is a UITextView then we are fine, if is UITextField you might have some problems because you don't have access to current cursor text position like un UITextView.
(You might check UITextView and UITextViewDelegate methods)
If you just want to set a string and don't mind current cursor text position, then you don't need a keyboard. (I think this is the case of Tipulator)
BTW: I just saw Tipulator in youtube and there is no necessity of a keyboard for doing that.
Judging by the looks: It's a custom UIView subclass. Basically, it's just a panel with 11 buttons on it, so it should be rather easy to do.

Changing the text in a UITextView at runtime

I have a ViewController consisting of just a textView. In its viewDidLoad method, I simply initialize the textView and add it as a subview. In my main ViewController class, when the user presses a button, I switch views and display the view that has the textView. I am trying to change the textView's text however it is not working. Can I not change the text of a UITextView at runtime?
Thanks.
You should keep a reference to your text view.
If you do, then make sure that the reference is correct and valid before setting the new text.
In general, it always helps when you post a problematic code - this way it is much easier for us to help you...