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?
Related
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.
I have a case where I would like to make an already existing UIButton unresponsive and basically act as a UILabel. Doesn't anyone know a way of doing this programmatically in c preferably?
Set it's .userInteractionEnabled property to false
If you disable Interaction still you can see the UIButton blinking for click. Better you can uncheck Enable button property from Accessibility.
:
This will help to achieve your requirement.
You can disable userinteraction on your button something like,
yourButton.userInteractionEnabled = NO;
And your button will not respond more!
Disbale User Intercation by writing this code:
yourButton.userinteractionenabled=NO;
I am trying to get data into textfield from UIbuttons, but when the user clicks on the textfield, the keyboard popups and if I disable the user interaction textfield, it won't allow me to use deleteBackward() method, Used when user wants to delete a character of text field.
Help please.
You should create subclass of textfield and override canBecomeFirstResponder method.
To NOT display keyboard, return false from canBecomeFirstResponder method.
UPDATE
If you want cursor in your textfield when you touch it, juts assign blank view to inputview.
textField.inputView = UIView();
Why don't you instead of using deleteBackward() just set text without last character? This way, you can just disable userInteraction and get exactly same results.
Along with this, you can consider using UILabel, instead of UITextField
put textField.resignFirstResponder() it will stop popup keyboard
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.
Im trying to copy the content in a UILabel but without hiding the keyboard, the problem is that when I show the menu of copy in the label the label becomes first responder and the keyboard resign, but I want to do that without hiding the keyboard, is there a way to do that?
It is not possible with UILabel.
You should use UITextField for that. Just disable editing.
AFAIK, you can't do that. But I think you can have a work around for that. Instead of not hiding the keyboard, why don't keep track the current active text field and then active it after user press copy. You can use UIPasteboardChangedNotification to know when user pressed copy. For example:
self.lastActiveTextField = aTextField
-(void)pasteBoardDidChange:(NSNotification*)notif
{
[self.lastActiveTextField becomeFirstResponder];
}
I think so u r looking something like this project.
UILabel with UIKeyInput protocol implementation
https://github.com/hackiftekhar/IQEditableLabel
I think, it is not possible, there can be only one first responder at any time. If the keyboard is shown because of another UI element, then when you try to copy the content from UILabel, the OS has to transfer first responder from other element to UILabel, as there is no need of keyboard for UILabel, the keyboard will hide automatically. So, you have to make changes to your elements to fix this problem or use third party UI elements who can fix your problem.
Every UIView component has a method called: canBecomeFirstResponder. He is read only, but you can subclass the UI object and override the getter:
- (BOOL)canBecomeFirstResponder {
return false;
}
I didn't do the test, but if the "become first responder" is the problem, that should solve it.