Changing UITextView after a UIButton has been pressed - ios

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"];
}

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.

How to make the bottom toolbar float just above on the soft keyboard when the Textfield get focus

I add a toolbar in bottom of UIViewController and put a TextField on the toolbar, but when I hit the TextField ,the textfield is covered by popup-ed soft keyboard and Can't see it.
So, How to float the toolbar just above on the soft keyboard when the Textfield get focus.
There is a property called inputAccessoryView. When a textField is tapped you can call it like this:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
textField.inputAccessoryView=self.accessoryToolBar;
return YES;
}
this will call the toolbar on top of your keyboard.

Set text inputed from keypad on UILabel on UIButton click

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];
}

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

Resources