Set text inputed from keypad on UILabel on UIButton click - ios

i want to write the text to UILabel which is inputed from iphone's keypad. when i tapped button as in screen shot. how i can do that ? i don't want to use Textfield.

-(IBAction) buttonTapped {
[self.yourlabel setText:[textField text]];
}

Add a UITextField (you can name it hiddenTextField) some where, and set it hidden in view, so it'll become invisible to everyone, in viewDidLoad method of that UIViewController write,
[hiddenTextField becomeFirstResponder]; //it will make UIKeyBoard show on screen
On your UIButton action write,
- (IBAction)myAction {
myLabel.text = hiddenTextField.text;
//Don't forget to set `hiddenTextField` delegate to self.
[hiddenTextField resignFirstResponder];
}

Related

how can i edit the app extension custom keyboard,when use UIButton

I want to edit my customKeyboard when I tap the UIButton that in my custom keyboard.
I have already add a UIButton in the keyboard,and the code like this:
- (IBAction)resignKeyboardButtonDidTouch:(id)sender {
[self.view endEditing:YES]; // it doesn’t work
}
You can resign keyboard for specific textField like,
[yourTextfield resignFirstResponder];
So, try this. You can set same tag to your button and textfield to identify particular textfield.

Changing UITextView after a UIButton has been pressed

I'm trying to change a UITextView after a UIButton has been pressed, for example my text view says "bananas" and when a button is press the same text view must change to "are delicious."
You need to set up an outlet to your UITextField (calling it textField in this example) and an Action to your UIButton.
Your action would look something like this:
- (IBAction)buttonPressed:(id)sender {
[self.textField setText:#"are delicious"];
}

iOS hide default keyboard and open custom keyboard

I have an UITextview, when user taps on UITextview i need to hide the default keyboard. For that i have done,
[myTextView setEditable: NO];
So the keyboard is not shown, here i have created an Custom View with UIButton, i need to show this UIView when the user taps on UITextView, for that i have done,
textViewDidBeginEditing{
//Here i have added UIView as subview
}
But this method is not working because of,
[myTextView setEditable: NO];
and i need to close the UIView when user clicks the close button inside the UIView
You should be using resignFirstResponder instead of setting the UITextView to not editable. This will hide the system keyboard.
[myTextView resignFirstResponder];
If you want to use a different view for the keyboard then the system provided one then set inputView on the UITextView to the custom view you want to be used in place of the system keyboard.
myTextView.inputView = myCustomView;
Perhaps using textFieldShouldBeginEditing instead of setEditable: NO works?
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//Here i have added UIView as subview
return NO;
}

UITextField and UIButton

There is a textField and a button in my view, and if the
textfield is empty I do not want to user can click the button.
When user text something in the textfield, the button will bu
clickable.
How can I do this? Thank you.
for your UITextField, you can set:
[textField addTarget:self action:#selector(editing:) forControlEvents:UIControlEventAllEditingEvents];
Then in your editing: have:
-(void)editing:(UITextField *)sender {
myButton.enabled = ![sender.text isEqualToString:#""];
}
Listen for changes to the text field. As the text changes, update the button's enabled property based on whether there is text or not. Of course you also need to set the button's state at the beginning as well.
// Setup the text field change listener (this can be done in IB if appropriate)
// Put this in viewDidLoad if not using IB.
UITextField *myTextField = ... // a reference to the text field
[myTextField addTarget:self action:#selector(textFieldChangedAction:) forControlEvents:UIControlEventEditingChanged];
// Initialize the button's state (put this in viewDidLoad)
myButton.enabled = myTextField.text.length > 0;
// The method called as the text changes in the text field
- (void)textFieldChangedAction:(UITextField *)sender {
myButton.enabled = sender.text.length > 0;
}
If you want, you can "hide" the button by setting the alpha value of the button to 0 and when the textfield is at least one character long, then set the button's alpha value to 1 to "show" the button. I think this conceptually is easy to do and very presentable to the user.
Set the textfield.delegate to self
Then in delegate that is textfielddidbeginediting
(
Check is textfield is #""
Then disable the button
Else
Enable the button
)
And there is one more. Delegate u can use
Textdidchangecharacters
And in viewdidload first state of the button should be disabled

Bringing up the iPhone keyboard by clicking a button?

How can I bring up the iphone keyboard by clicking a button - I haven't created any text fields. My intention is to have labels that hold a single character.
Other people have asked this and it has been answered but it was from years ago and I didn't understand what people meant in there responses.
Thank you for any help in advance.
Only way you could do this is via hidden UITextField, and set that textField to becomeFirstResponder
you could hide the text field in your code liket his textfield.hidden=YES;
or you could hide the textfield from nib file also by going into the attribute inspector and tick the Hidden property
You could have a look at this UIKeyInput- Displaying keyboard in iPhone without UITextField or UITextView, I have not tried myself this
Attach the button to a touchUpInside event and call becomeFirstResponder on the textView or textfield:
Here is an example (to bring it up when a text view is clicked):
-(IBAction)buttonClicked:(id)sender{
[textView becomeFirstResponder];
}
-(void)ButtonClicked
{
[textFld becomeFirstResponder];
[textView becomeFirstResponder];
}
use this method
You can add a hidden UITextFeild as tempTF and when the button clicked. call becomeFirstResponder of this textFeild:
[self.tempTF becomeFirstResponder];
To Hide textField:
UITextField *tempTF = [[UITextField alloc] init];
tempTF.hidden = YES
or mark Hidden ir your Interface Builder

Resources