IOS: UItextfield disabled - ios

When we push on a textfield, a cursor appears in this textfield, but I don't want that this cursor appear. I want to make this textfield disabled, where you can't write inside.
How can I do this?

Can you set enabled property/userInteractionEnabled of text field to No in ViewDidLoad() using the code
textField.enabled = NO;
or
textField.userInteractionEnabled = NO;

If you're working with storyboards or .nib files and you want it to start out disabled you can also easily uncheck the enabled property in interface builder for some time-saving.

Related

User secure text keyboard without secure text enable in text field?

I want to use below image keyboard with ".?123".
When we enable secure text for a password in UITextField it displays below the keyboard.
I want to display this keyboard without secure text in other UITextField.
Let me know if anybody has a solution for this.
You can set keyboard type from attribute inspector from story board..
You can also set it programatically like this
txtField.keyboardType = UIKeyboardType.default
So you can check it like this...
if txtField.isSecureTextEntry {
txtField.keyboardType = UIKeyboardType.default // whatever you want to set.
}
By default iOS Doesn't change the keyboard either the entry is secure or not.
Keyboard style is an independent property from data entry security.
You can change the keyboard type to .default, .numberPad, .phonePad, .email, .url by setting it to the property keyboardType of UITextField object.
yourTextField.keyboardType = .asciiCapable
You can also achieve above task from your Storyboard or Xib to know how to use in Xib and Storyboard please refer to Mahendra GP's answer above.

How to replace uitextField with uitextView when touching uitextField (swift 2)

My question is how to replace uitextField with uitextView when i touch the uitextField.
What can i do in this situation? i tried to add uitextView and then add uitextField in the same area and when i touch the uitextField it will removed but it doesn't work. my code is
textField.enabled = false
Maybe my code is not right or my idea.
I do this to have Placeholder in UITextView like this video and I thought that this is the best way to have it because i tried many ways but all do not work perfectly.
I need your help guys .
It's the property hidden that you should use and not enabled.
With the latter you can control if the user can interact with the view (enabled = true) or not (enabled = false)
The former instead make the view invisible when set to true and visible otherwise.
What you want is to do this
textField.hidden = true
textView.hidden = false
after the user tap on the textField.
Be sure to have the textView already in the right place where you want it to appear.
You might also want to handle the keyboard :)
Why don't you use a UITextView directly from the beginning?

UITextView - How to prevent keyboard to be shown when using readonly TextView

I am using a UITextView to show some text but I don't want the user to be able to edit it. I have tried setting the property Editable to false, but the keyboard still shows when I touch on the text.
Is there any other property I could set to stop this behaviour?
Try
textView.userInteractionEnabled = NO;
You sure you set the property correctly? Or Is your textview nil? You should check it, if everything is OK,then
textview.editable = NO;
should work.
BTW, do not usetextView.userInteractionEnabled = NO; because if your text is very long, you cannot scroll textview to show more
You can do this using the solution that "MarkHim" posted, or you can do this from the storyboard.
Just check/uncheck the boxes that say "Editable" and "Selectable" in the "Behavior" section. By unchecking "Editable" the keyboard will no longer come up.

Click a button to show the keyboard iOS

I want to realize the function: when I click a button, a interface of keyboard will come out in a dependent interface. How can I do it? Just for iOS.
You need to add to your current view UITextField with frame = CGRectZero, create a reference to that textField in code and then on pressing button call becomeFirstResponder on textField.
You need to add an UITextField to your view and call then [myTextfield becomeFirstResponder]; Its possible to set the hidden attrribute from UITextField to YES - so the user will never see the textfield. After Keyboard input is finished you can remove the UITextField with removeFromSuperview.
Maybe a little bit dirty,but thats the solution I used often. I wonder if the SDK provide another possibility.

How to disable keyboard but enable UITextFields when using UIDatePicker?

This one is kind of hard to explain, so ask any questions you need to clarify the question. I have an iPad app (XCode 4.2, iOS 6, ARC and Storyboards).
In this app, I have a UIPopover that contains a UIView with two (2) UITextFields in it and a UIDatePicker. (see image). When I go to that scene, I have unchecked userInteractionEnabled on both textFields to prevent the keyboard from responding, which works, but doesn't allow the other UITextField to be accessed after the first one. I tried [oFinishTime setInputView:oTimePicker]; but it takes the timepicker and moves it outside of the popover, which is unacceptable.
I have touchUpInside events "wired" for each of the textFields, but neither one gets called when tapped due to UserInteractionEnabled being unchecked. I could remedy this whole thing if I could have it enabled and set a flag in the action event.
How can I enable both UITextFields yet prevent the keyboard from showing? I will be happy to post any relevant code you need to see.
May be I did not understand your problem correctly , but it seems like you all you are trying to do is Open a picker on tap and display the value set in UIPicker. You are not really using any functionality of a UItextField. A label or a button might serve the same purpose and save you from doing the extra work of disabling the keyboard.
In any case if you want to use textfield and disable keyboard picker appearing as the input view and have your own input view to it, you could do
-(void)textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
}
You could take a look at this:
Display datepicker on tapping on textfield
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing.
assign delegate for each textfield and in the delegate method verify if its the one which should open picker instead of keyboard.
If it is the one then return NO
else YES
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if (textfield == startTimeTextField)
{
[self openPicker];
return NO;
}
return YES;
}

Resources