Issues with clearButtonMode, showing button for empty text - ios

How do you get the clear button to appear on a UITextField when the placeholder is visible? The following works but is only visible when selected and text has been entered.
Clear Button (when text entered)
textField = UITextField(frame: someFrame);
textField.placeholder = "Untitled";
textField.clearButtonMode = .always;
textField.clearsOnBeginEditing = true;
How do you get the clear button to appear while editing and empty?

Related

Showing rightView for UITextField only if empty and not selected

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.

UISearchBar iOS 8 clarification

I'm trying to get special behavior of UISearchBar. I want never to show "Cancel" button (this part i'm already implement) and show Bookmarks button always.
But if i hide cancel button, bookmarks button is hide too in editing mode (only if searchBar.text.length > 0)
How i hide cancel button:
UITextField *textField = [searchBar valueForKey:#"_searchField"];
textField.clearButtonMode = UITextFieldViewModeNever;
Picks:
My question is how can i always show only bookmarks button?
You also need to set this:
textField.rightViewMode = UITextFieldViewModeAlways;

UITextField add cleared icon [duplicate]

Some apps have this nice little white circle with an gray x in there UITextField. How can I add this to an UITextField and delete the text when it is tapped?
To add a button like this, you can use the clearButtonMode property of an UITextField.
The code will be like this:
// Show cancel button never
textField.clearButtonMode = UITextFieldViewModeNever;
// Show cancel button only when you're editing text in textField
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
// Show the cancel button only when you aren't editing the text
textField.clearButtonMode = UITextFieldViewModeUnlessEditing;
// Show always the cancel button
textField.clearButtonMode = UITextFieldViewModeAlways;
Check out the clearButtonMode property.

keep contents of textview till a button is pressed

I have been looking for a code to keep the contents of the textview ,till i click on a back button or a done button on the same page. But when i gave the code:
(void)textViewDidBeginEditing:(UITextView *)textView{
myTextView.text = nil;
}
Every time(even before completing the text) , if i press the return button of keyboard and click on text view again to type the rest, the already existed text clears away.
I have kept the above code for clearing the default text "Enter your text", when the textview is shown for the first time.
I have been working by setting booleans, but could't get the result! Please if someone could clear me out of this . Thanks in advance.
Do it like this
(void)textViewDidBeginEditing:(UITextView *)textView{
if ([myTextView isEqualToString:#"Enter your text"]) {
myTextView.text = nil;
}
}
This code will check that is your text is equal to Enter your text and if it is than it will clear otherwise not.

uipickerView is in the middle of view and change default inputview position

I have create an iPad application of data entry.
I use a Tableview for data entry end the cells is custom cell.
For the date I have created a textfield with a pickerview (UIDatePicker)
pickerView = [[UIDatePicker alloc] init];
[pickerView sizeToFit];
pickerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
pickerView.datePickerMode = UIDatePickerModeDate;
self.dateField.inputView = pickerView;
The problem is that when I press on the textfield, it shows the pickerview in the middel of view and when I press the "Done" button to hide the pickerview the defaul position of the inputview (default keyboard) is not in the bottom of view but in the middle. If press again on the "Done" button of the picker view, the keyboard position increase its x value.
The problem is because when I show the pickerview, the keyboard is undocked (iOS5).
Is it possible to set the undocked - docked state of the keyboard in the code?
I have insert image of my problem:
Foto default keyboard
Foto Pickerview

Resources