Showing rightView for UITextField only if empty and not selected - ios

I'm showing a UIButton for the rightView property of a UITextField. I only want to show this button if the text is empty and the user is not editing.
I'm setting the rightViewMode property to UITextFieldViewModeUnlessEditing which hides the rightView if I'm editing but I also want the right view to hide if there is text in the text field even if it's not selected. I'm not sure how to setup this behavior.

Related

Show Clear Button of UITextField even it is empty

I have a UITextField for search in my Application.
When user taps on the Clear Button in the right of the Search Text Field I need to hide this textfield.
So, can I show the Clear Button then TextField is empty? I need to do it always to provide the ability hiding TextField.
Just create a Custom button and set it as rightView for your TextField
UIButton *cleanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// Set clear image for your button
[cleanBtn setImage:img forState:UIControlStateNormal];
[cleanBtn addTarget:self action:#selector(cleanTextField:) forControlEvents:UIControlEventTouchUpInside];
yourTextField.rightViewMode = UITextFieldViewModeAlways;
yourTextField.rightView = cleanBtn;
I tried to fix this issue with creating a custom button and setting the rightView of my text field. It did not solve my problem. There is no button on the right view.
I have added UIButton in Interface Builder using Auto Layout and placed it on my text field. It works. It's strange solution but it works.

Rightview on UITextField does not disappear on editing

I have a rightView on UITextField with the mode UITextFieldViewModeUnlessEditing, so it should disappear when we are editing the textfield.
But now when I start editing the textfield programatically when you press the rightView (an edit button) the rightView does not disappear immediately. It only disappears when I start typing something.
So why does editing for a UITextField only start on typing and not on becoming first responder? How do I fix this?
Add the < UITextFieldDelegate > to your interface.
Then set the delegate or your textfield to self (either in IB or) for example in viewDidLoad:
self.theTextField.delegate = self;
Add this method to your .m :
-(void)textFieldDidBeginEditing:(UITextField *)textField{
// Whatever is supposed to happen when you begin to edit the textfield happens now
}

How to set keyboard as inputview in UItextfiled

I have one UItextfiled and in viewdidload i set his input view property as nil like this.
textField.inputView = nil
In in my view i have one button when i click on the button i have to set the textfield's inputview property as keyboard how can i do this.please help me.
I'm not exactly sure what you want to do, but probably you want your textField to became active, with a keyboard. That is done with
[textField becameFirstResponder];
and other way around is
[textField resignFirstResponder];

TextField text not displaying from UIPopOverView

I have a UITextField on main ViewController and once I touch down the Textfield UIPopOverController with UIPickerView opens which is from other class.now I want when I select any value in Pickerview of popovercontroller the selected value should display as UITextfield text and In main Viewcontroller when I pick any value in Pickerview a method calls to print UITextfield text but textfield.text comes always null. but I used the Appdelegate sharedAppdeledatewhich give me value on tapping on pickerview but when i used it to text the textfield it gets null. what should I Do.
and I want to add value on the UITextfield without removing the top view which is pickerview
pass your parent class object to your popovercontroller class and you'll be able to have access of the parent class property in child class and then you'll be able to set your textfield value selection on picker from popovercontroller class

how to disable uikeyboard of textview ,if the editing mode enabled

How to hide/disable keyboard ,if the textview editing is enabled.
I only want to that user can only be able to select the text and can't be allowed for entering text.
Because selected text will be converted in to image for move animation.
User will not be allowed for entering any text in textview so that's why keyboard should be hidden or disable ,he will be allowed only for text selection.
uitextview.editable = NO; or set checkmark in IB. It will allow to select text with options - Copy and Select All without keyboard appearing. Tap on the word and hold to select text.
ok just uncheck the behavior of you UItextview in .xib file.
Something to try it the 'editable' setting doesn't work out is to create a UIView that's hidden and out of the way somewhere and assign it as the inputView for the text view. If that property is non-nil, the view it contains will be shown instead of the keyboard.
Such as:
self.textView.inputView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)] autorelease];
try this
yourtextview.UserinterationEnable=No;
This will make the keyboard disappear:
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
This what you want to do?

Resources