I have an iPhone app with a UITextView. I'd like to be able to paste the clipboard contents into it without showing the UIMenuController.
I tried calling the paste: method on the UITextView, and on the first responder, but neither of those things worked.
I was able to implement this by writing a bunch of code to read text from the clipboard, insert it in the UITextView's text property, and update the selection range. I also added support for undo/redo. But it seems like there ought to be an easier way. Is there?
Did you try paste with nil sender?
[theTextView paste:nil];
as per UIResponder docs
Did you try making the UITextView the first responder?
I checked out the headers to the UITextView object, but I couldn't find any documented method called -paste; also, looking over the NSPasteboard class suggests to me that programatically setting your text was the right way to go.
If pasting text is important to your app, I would consider setting up a class to handle it; maybe even make it a singleton if it was important enough.
Good luck!
Related
I've a UITextField, I need to color some specific word in a gray
Is there a direct solution?
If not, I think If I got the Source code for setTextColor method, try to conditinoally change its implementation (may be through a Category or even subclassing).
It's not possible as is. To implement that kind of feature you have to use CoreText.
For more info read this great tutorial: http://www.cocoanetics.com/2011/01/befriending-core-text/
I have one question, may be it is very simple, but I do not know about this nothing...
For example, I have an application, application with textfield, I want to know two things.
First: Is possible to switch keyboard when application in runtime?
Second: how I can switch type of keyboard(Russian, English, Swedish, etc.) in my application*?
*-without going to Settings->General->Keyboard->add new keyboard.
Not sure about changing languages (I did find this other post about it: change input source language programmatically OSx), but changing the keyboard is pretty easy. Here is a one line example:
textField.keyboardType = UIKeyboardTypeURL;
Take a look at the UITextInputTraits protocol reference for more info. Then the question comes in where to implement this. I am assuming that you want to check conditions right before the keyboard comes up, you may have to implement UITextFieldDelegate protocol (and maybe using the field's tag to see which field the cursor is in).
Hope this helps.
I have an app that uses UiWebViews, and I need to not show the keyboard for a text field within such a view. I provide my own buttons that insert the limited sorts of text the field allows, but I also need to allow pasting (I will filter what gets pasted) and adjusting the cursor position. Any way to do this?
It looks like this can't be done, I've researched it further and that's pretty clear. I don't want to accept a wrong answer, so I figured I'd just answer this myself and say: can't be done.
if you just want the textField do normal things except the showing keyboard action, you could subclass UITextField and overwrite the touchesBegan/Moved/Ended, just call super touchesBegan/Moved/Ended and add additional code which would hide the keyboard, if you have a reference to the keyboard ( you may figure it out urself how-to ), call the method : [keyboard resignFirstResponder], you may try to Category the UITextField class so you would have the reference to the keyboard ( if it's private ) - but not recommended because categorying may break our project design, but if you just need it for the only purpose, give it a try. Hope it helps.
i created persian custom keyboard , my letters type on UITextView , but the UITextView dosn't support paste function ! why ? i don't check the editable option .
In your UITextViewDelegate, you can try implementing textView:shouldChangeTextInRange:replacementText: to see what, if any, text is being pasted. I'm not sure if it's going to be called on the paste event though.
If the text view isn't editable, the user can't paste to it.
I am wondering how Amazon did the highlight/note popup buttons in the Kindle app. After reading about UIPasteboard, UIMenuController, UIResponder, and UIResponderStandardEditActions, I am able to turn on or off standard edit actions (i.e. copy, cut, paste, select, and selectAll). However I haven't found a way to add a custom action yet. I would really appreciate it if I could get a pointer.
Thanks in advance!
Chris
(source: sampletheweb.com)
Edited by balexandre (added image instead link)
It looks like Amazon implemented their own custom view that mimicked the appearance of UIMenuController. I believe they did this rather than use SPI because if you click and hold on the Highlight cell, the arrow does not highlight, when it does in the real UIMenuController.
I don’t think there is a public interface to these controls, you’d probably have to code them yourself. (Or maybe figure out the private API, but that’s a slippery slope.) I am not sure about that, though, maybe somebody will prove me wrong.
That's a good point about the arrow part of the Notes/Highlight popup menu not highlighting, so they must be implementing their own.
However they are also obviously using a UIWebView, because it's recognizing tap and hold and they can highlight the text, and you can't get touch events from a UIWebView, much less get the information about what's selected. So how are they doing that?
This would be very useful for us to be able to do as well.
Use DTMenuController http://www.drobnik.com/touch/2010/01/dr-touchs-parts-store/
Costs 100 EUR ^_^
Custom menu items can be added via the UIMenuController's menuItems property. See Apple's UIMenuController docs.
the javascript part can be managed with jQuery, that's a fair simple and powerful library. i'm using it for resizing and rearranging things in a webview and it works great :)