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

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.

Related

Adding UITextField() to UI programmatically, cannot tap on field to get keyboard

I've been doing iOS development for a long time and I've never run into this before. The UITextField appears in the UI, it is correctly sized and placed by the constraints I've given it, but when I tap/click on it and doesn't respond. The cursor doesn't appear in the field and the keyboard doesn't show up.
let textfield = UITextField()
textfield.translatesAutoresizingMaskIntoConstraints = false
self.contentview.addSubview(textfield)
textfield.keyboardType = .numberPad
textfield.borderStyle = .roundedRect
textfield.text = "stuff"
// and then I set up constraints which are working as expected
I've double checked my simulator to make sure it isn't a soft keyboard issue.
I don't need any specialized UITextFieldDelegate behavior, I just need to standard behavior that tapping will cause it to become first responder, set the cursor there, and open the keyboard. When I add a UITextField via a storyboard, I don't need to set a delegate in order to get this behavior, so I can't imagine I would need to create specialized delegate code in order to get this basic behavior.
Just to test if something else was wrong, I've tried programmatically forcing the textfield to become first responder and that works.
I've tried forcing this to be true, just in case:
textfield.isUserInteractionEnabled = true
but that didn't change anything.
Any ideas? Why isn't my programmatically created UITextField accepting taps?
EDIT: Got an excellent suggestion to check out the Hierarchy Inspector to see if anything else is on top of it. It looks like I don't have anything on top of it: Here's a screenshot of the sim and of the hierarchy inspector turned a bit to the side so you can see the layers.
There isn't anything in front of the UITextField. (The UITextField has like 4 internal layers, but nothing is in front of them.)
As we have discussed in the comments under the OP, it's always a good idea to check the view hierarchy in the View Hierarchy Inspector to see if the frame is laid out properly and also if perhaps some other view isn't covering the other view which should become the first responder.
The view hierarchy inspector can be found here once the app is running on a simulator or a device.

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?

iOS - Can I disable accessibility on cell.textLabel.text?

I have an app that contains a view with a cell that uses the built-in cell.textLabel and a custom UITextField in cell.contentView.
I am working with Voiceover and accessibility and the desired behavior would be that whenever I tap anywhere in the cell, the accessibility element for the UITextField would be selected.
The behavior that I am actually seeing is that the cell.textLabel accessibility labels are taking over. When I don't have cell.textLabel set to anything, everything works as expected. I have also attempted to set the "isAccessibilityElement" property with no luck:
[cell.textLabel.text setIsAccessibilityElement:NO];
Does anyone know how to make this work the way I want?
I was able to figure this out using this:
cell.textLabel.accessibilityElementsHidden = YES;

Can I make UITextField invisible?

I checked out iPhone: How can I make a UITextField invisible but still clickable?, but the OP has something else going on and the answers didn't seem to help me out of my fix.
I have a UITextField in which the user has to enter text. Instead of the standard UITextField graphic, I want to use a lovely graphic that's been designed for that purpose. The user would still need to be able to enter text and see the text s/he's entering, but I need the textfield to be invisible so that the graphic can show from underneath it.
How can I do this? Or is there another way to do what I'm after?
Adding my comment as an answer. You can try this,
[textField setBackgroundColor:[UIColor clearColor]];
And then set the border style as UITextBorderStyleNone.
something like:
yourTextField.borderStyle = UITextBorderStyleNone;
should do it
Another solution would be hiding the UITextView itself and just adding a transparent button that will call the keyboard to display.
Otherwise, the other answers should work.
Easiest option is to do it in interface builder. Choose the first uitext field style with no border and that's it.

IOS: UItextfield disabled

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.

Resources