How to make UIAlertController's message selectable - ios

How to make UIAlertController's message selectable with a long press gesture recognizer?
Is there anyway to do this?

UIAlertController doesn't provide text selection functionality. If you want to do copy this then you could alternatively provide a button on your UIAlertController that copies a string to the pasteboard.
OR
Add a UITextField to UIAlertController, by this you can select the text in UITextField, to stop editing in it, implement delegate method for UITextField.

Related

Is it possible to add a Done key to ALL keyboards in an app?

Is it possible to add a done or cancel key which dismisses a keyboard to all keyboards in an iOS app? There are several posts asking how to dismiss a keyboard via a cancel or done button, but the solutions are on a field by field basis.
Are there any solutions that add this functionality globally so the code wont need to be duplicated for each textfield/area in an application?
Like #silentBob says in his answer, the inputAccessoryView of a text field is the view that’s displayed immediately above the keyboard when the text field is the first responder. If you didn’t want to write an extension on UITextField to override the -inputAccessoryView method, you could also create a subclass of UITextField to do the same, which would make it easier to determine which method is going to be called. You could also have multiple subclasses of UITextField to customize which button(s) appear. If you have a text field in a storyboard, you can simply change the class to your custom subclass, so while you have to go through and make those changes, you don’t have to do it in code.
Yes, you can add an extension to UITextField class, which should add a UIToolbar with Done and Cancel actions as UITextField inputAccessoryView.
Well, In that case you have to customise the keyboard, built your own keyboard and do whatever you need to do with your key in the keyboard.

How to make keyboard not to popup on clicking of a TextField in swift?

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

How do I make it so next button can't be pressed on keyboard without text?

Working on an app and wondering how to make it so the next UIButton on the UIKeyboard cannot be pressed unless text is entered in the UITextfield?
Checkmark "Auto-enable Return Key"
You should be implementing textFieldShouldReturn in you UITextField Delegate. There you can check whether a valid string has been entered into the text box and allow the next button or not.
Documentation here

How to disable interaction on NSTextAttachment?

In a UITextView with editable = YES and selectable = NO, I want to disable interaction on NSTextAttachments. To be more specific, I don't want long presses on NSTextAttachments to highlight the attachment images. I want these long press gestures to be passed to UITextView as normal text selection gestures.
What I have tried:
textView:shouldInteractWithTextAttachment:inRange: can prevent the action sheet but can not prevent the temporary highlight of the attachment image nor can it make these long presses be handled as text selection gestures.
UITextView has several installed gesture recognisers. There is one that is a subclass of UITapGestureRecognizer which you can disable.

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.

Resources