copy text from textfield with not enabling keyboard - ios

i have a uitextfield and some text on it, i want to know how to create a code that my user touch the field and can copy the txt to use for something else.
my uitextfiled.enable = no;
thanks

As far as the copying goes, you need to check out the UIPasteboard Class. Using that class, you can put text onto the pasteboard very easily.
For not enabling the text field, you can simply leave it disabled, but capture the touch event anyway.
For the pasteboard, try going through this tutorial.

I you are able to use UITextField class instead you could set the editable property to NO. Selecting text will still be possible.

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.

Cursor issue while creating Custom keyboard with UIView

My requirement was to make a application specific keyboard i.e with a different theme and different key contents as compared to the default keyboard. But the way Apple states to implement keyboard requires user effort to add it through Settings->General->Keyboard which I don't want.
So, for that I tried to implement it using a UIView and making it the inputView for UITextView and it is working perfectly fine except for one issue. I added a functionality to add a linebreak in the textView. For that the code I used is
textView.text = "\(textView.text)\n"
Now, whenever I add a linebreak through keyboard, line is changed, but a new cursor appears to blink above the old cursor. I don't know how to get rid of that.
To explain the problem in a better way, here's a GIF image of the issue.
Please help.

Create custom keyboard within app not external

How am I able to create a keyboard that is already enabled in the app, or is it just buttons put next to each other to make it seem like a keyboard. Like the image below
http://i.imgur.com/qIoxR0a.png
you can use to the UIButton element or UIView with TouchBegan. But don't keyboard extension because different controller.
You can use ETCustomKeyboard which is mostly like same as you need.
And the output of that is show into below image:
You can modify this as per your need.
And HERE is one more same like that.
Hope this will help.
Create the keyboard as an ordinary UIView, and make it the inputView for your text field. There is more information in Apple's Custom Views for Data Input page.

Can I implement "select" and "copy" on UILabel when it has a long press just as UITextField (UITextView、UIWebView), and how?

Please give me a hand~ I wanna know how to make UILabel have a system Clipboard(e.g. copy and select) like UITextField (UITextView、UIWebView) when it has a long press, which makes me can copy the text I want. I have read some demo on Github, however, they always only contain copy function, which makes me can't choose the text I want to copy. At present I wanna implement "select" on UILabel but I don't know how to work out.
Can I use UITextField without editing function? But once I turn off editing function, there is no system Clipboard when it has a long press.
Or if there is a simpler method to work out? Thanks!
You're gonna have to implement it yourself. There isn't anything too special about any of the system text views, just read the docs for UIPasteboard, specifically around -[UIPasteboard setString:]. The rest just comes down to how you want to implement the UI. For that I'd recommend looking into subclassing UILabel just to keep everything tidy; UIMenuController for showing the callout view; implementing -canBecomeFirstResponder, -canPerformAction:forSender:, and -copy: to customize the callout actions; and UILongPressGestureRecognizer for triggering everything.

IOS 8:custom Keyboard with undo and redo button

I have developed an IOS 8 custom keyboard. I want to give it "undo" and "redo" functionality, like the default system keyboard. I have tried it in different ways but was unable to find a good solution.
We can interact with a Text Input Object textDocumentProxy with the methods
insertText
deleteBackward
documentContextAfterInput
ocumentContextBeforeInput
But I was unable to find any way of implementing "undo" and "redo" functionality.
I think we can NOT implement these function (undo,redo)
According to https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html
Because a custom keyboard can draw only within the primary view of its
UIInputViewController object, it cannot select text. Text selection is
under the control of the app that is using the keyboard. If that app
provides an editing menu interface (such as for Cut, Copy, and Paste),
the keyboard has no access to it. A custom keyboard cannot offer
inline autocorrection controls near the insertion point.
I think there are many case that content of textfield changed and you can not know when it changed, how it changed. If we can not know, we can not know to undo to where too. I think so.
I'm developing Custom keyboard extension like you and I have many problems. (eg: how can we know the current cursor to get current text selection...)
My question: Current text selection in CustomKeyBoardExtension (hope somebody know)

Resources