How to hadle copy: paste: cut: events in UIWebView?
As Apple says, we can not subclass UIWebView,
so how can I handle UIResponderStandardEditActions?
Maybe someone faced with such a difficulties...
I need to implement custom copy,cut,paste in order to copy/paste html (RTF text, some custom html elements).
In addition, I have 2 webviews, so if I paste some elements in one, another one should reply for this interaction.
Unfortunately, I think you are going to have to make your own copy/paste menu.
Using the answer from this question you can set up custom copy/paste buttons, and you could handle everything you are trying to do through those:
[[UIApplication sharedApplication] sendAction:#selector(cut:) to:nil from:self forEvent:nil];
Also, this question shows how to make a custom UIMenuController and use the UILongPressGestureRecognizer to get it to show up on the UIWebView.
I hope this helps. Someone else may know an easier way, but I think this way will work at least.
Related
I'm trying to write a test tweak for iOS 8.3 using Theos.
This tweak will show a UIAlertView with two choices when the user taps on an application's icon.
I want to distinguish between the buttons, and to do so I need to add the UIAlertViewDelegate.
Following this example written by DHowett, I've adapted his code to run under iOS 8.3.
The code compiles and loads fine but no action is triggered when I tap on any icon.
If I simply hook into SBApplicationIcon with the correct method, action is triggered but this way I'm not able to distinguish button press.
Is this still a good way to add protocols?
You can cast the class you're hooking into to id<ProtocolName> when setting the delegate.
For instance, in your case it would be something like:
[alert setDelegate: (id<UIAlertViewDelegate>) self];
I need to show error message as a tooltip in iOS 8 but i don't know how to do it. What I want is something similar to the one shown in below image (I'm referring to the tooltip with messages Select and Select All):
There is a great collection of libraries which already target your problem.
For example have a look at: AMPopTip.
Then you could show the popover like:
self.popTip = [AMPopTip popTip];
[self.popTip showText:errorMessage direction:AMPopTipDirectionUp maxWidth:200 inView:self.view fromFrame:textField.frame];
and hide it:
[self.popTip hide];
Have a look at the github repo there are more examples for customizing this control.
You can find more which might suit your needs better here: cocoacontrols.com
I had a similar problem and wrote my own custom tooltip.
You can init with your custom view (i assume you write some delegations to detect actions within.) and present from anywhere.
Maybe not the best replacement of UIPopoverController but still works great. And a lifesaver for iPhone. Also highly customisable.
https://github.com/akeara/AKETooltip
Hope this helps.
I've been developing a custom keyboard for iOS 8, but stumbled upon a problem trying to send images using the keyboard. I did some research and it seems like there isn't a simple way to do this with UITextDocumentProxy because only NSStrings are allowed.
Am I either overlooking any simple ways to use a custom keyboard to send images and/or is there any way to work around this issue?
Thanks in advance
Apparently, you are not the only person to try a keyboard like this. If you look at the animated GIF on the site, the keyboard uses copy/paste to add the image to the messages.
The UIKeyInput Protocol, which is inherited by UITextDocumentProxy, has the following function:
func insertText(_ text: String) //Swift
- (void)insertText:(NSString *)text //ObjC
These only take a String or an NSString, as you already know. Because there are no other methods to insert content, it can be assumed that, currently, there is no other way.
Right now, I would suggest that you adopt a similar usage. When the user taps on the image, add it to the UIPasteboard. Maybe present a little banner on top of the keyboard saying, "You can now paste" or something, but that would be up to you to decide.
I want to handle copy/select/selectAll/Patse options of UIResponderStandardEditActions in webview. but i am facing problem, the copy action never called and also i observed that , in function((I have webview where i am displaying text using TTStyledTextLabel)..
canPerformAction:(SEL)action withSender:(id)sender
The copy: action never comes..but i do see that all other options like select , selectAll and cut actions getting called, even though the copy action never called in above function when i select text in webview the copy action is enabled but action never gets called..
Have you solved your problem yet? If you did please post your solution. I'm having the same problem with the paste function.
The solution I found, and I know it's not ideal, its to detect the events through javascript.
I use javascript to detect when a paste happens, call my objectiveC function to work with the data, and call a JS function from the objectiveC to paste the content on the webview.
I want to make some words in UILabel/UITextView become links so people can click it (like phone numbers, web links, usernames... etc).
I have tried using UIWebView but it loads texts too slow, not fast as a simple UILabel/UITxtView so I decided not use UIWebView.
I searched for many custom UILabel to do that and I found GLTapLabel which I think is the easiest way. But GLTapLabel only supports 2 types of links, it detects words which start by "#" and "#" (I want to create more types like phone numbers, web links ..etc). And 1 more issue is if I click a GLTapLabel's link insides a UITableView it will fire tableView:didSelectRowAtIndexPath: (I also asked in here GLTapLabel Inside UITableView but not solved yet).
So can you guys give me some advice?
For arbitrary links your best bet is to use TTTAttributedLabel, a subclass of UILabel that displays attributed strings on iOS 5. If you are using iOS 6+, UILabel supports attributed strings directly.
TTTAttributedLabel *someLabel;
[someLabel addLinkToURL:[NSURL URLWithString:someURLString]
withRange:[longerTextString rangeOfString:linkTextString]];
#pragma mark - TTTAttributedLabel Delegate
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
// handle the URL somehow
[[UIApplication sharedApplication] openURL:url];
}
You need to enable UITextView's dataDetectorTypes. This will allow you to have links for URLs and other types of data.