, Hello, everyone.
I'm developing my app which has a feature to post article from website.
This is a picture of UIWebview with UIMenuController.
It was possible to get event when user tap the button. but I can't find the way to get the text the user selected.
In UITextView case, it has 'selectedRange' property, so it is easy to get selection text.
UIMenuItem *facebookMenuItem = [[UIMenuItem alloc] initWithTitle:#"Facebook" action:#selector(facebookMenuItemTapped:)];
UIMenuItem *twitterMenuItem = [[UIMenuItem alloc] initWithTitle:#"Twitter" action:#selector(twitterMenuItemTapped:)];
[UIMenuController sharedMenuController].menuItems = [NSArray arrayWithObjects: facebookMenuItem, twitterMenuItem, nil];
[twitterMenuItem release];
[facebookMenuItem release];
I would like to get the selection text on UIWebView.
Does anybody have an idea or hint?
Thanks.
Or if you donʾt want to mess with Javascript you can just copy the selection to the pasteboard and then retrieve it by running:
[[UIApplication sharedApplication] sendAction:#selector(copy:) to:nil from:self forEvent:nil];
NSString *text = [UIPasteboard generalPasteboard].string;
Related
I have added an 'UIActivityViewController' this works very well but the "Print" button is not shown.
How can I add the "Print" Button? I will print out the actual PDF file which is shown in an 'UIWebView' named "background".
Perfectly: That not the URL will be sent by email oder post on twitter/facebook special the pdf as Picture
here is my code:
NSArray *items = #[self.background.request.URL.absoluteString];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {
};
activityViewController.excludedActivityTypes = #[UIActivityTypeCopyToPasteboard];
EDIT:
How Can I print out the actual PDF shown in UIWebView as Image?
And how can I add the Printer Button?
Try to explicitly include a UIActivity of type UIActivityTypePrint in your applicationActivities when initialising the activity view controller.
Hi can anyone tell me how I can make the Share Sheet in iOS 6 black? I know how to make Action Sheets black. I use this code for Action Sheet:
[actionsheetshare setActionSheetStyle:(UIActionSheetStyleBlackTranslucent)];
[Eded]
so does it look by default
Here is my Code I use: NSString* someText = #"";
NSArray* dataToShare = #[someText]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:#[someText]
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{}];
You need to set UIStatusBarHidden to 'NO' in your Info.plist. If you have this property set to 'YES', the UIActivityViewController always appears with a grey tint.
I believe that this is a bug and I have filed it as such on Radar (problem #12682274).
What code you have written, i just had the below lines.. shows the black translucent, check by using this..
NSArray* arr = [[NSArray alloc] initWithObjects:[NSURL URLWithString:#"http://www.google.com"],#"Hello Guys", nil];
UIActivityViewController* activity = [[UIActivityViewController alloc] initWithActivityItems:arr applicationActivities:nil];
[self presentViewController:activity animated:YES completion:nil];
The whole view is simple UIView with an collection view, you can use its subviews like below to modify as you like
activity.view.subviews
I have a UIWebView in my app,and it can perform the UIMenuController. And I add a Custom UIMenuItem to the UIMenuController(like "google it").
The code I add the UIMenuItem is:
UIMenuItem *searchItem = [[UIMenuItem alloc] initWithTitle:#"google it" action:#selector(searchWithSelectedText)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:searchItem]];
[searchItem release];
Now,the custom UIMenuItem can be shown and do the right thing after clicked.
But in ios5,the UIMenuItem is too wide when it be shown.
Can the custom UIMenuItem be set shorter like the system items?
Thanks.
This is the new system style, I don't think you can customize it.
Is it possible to override the captions in the "Copy" menu when the iphone user long-presses on some text? Essentially, I'd like to change the text to something like "Create a Note" instead of "Copy". Is that possible?
You can add custom menus via UIMenuController's menuItems property, something like:
UIMenuItem* item1 = [[UIMenuItem alloc] initWithTitle:#"One" action:#selector(DoThingOne:)];
UIMenuItem* item2 = [[UIMenuItem alloc] initWithTitle:#"Two" action:#selector(DoThingTwo:)];
[UIMenuController sharedMenuController].menuItems = [[[NSArray alloc] initWithObjects:item1, item2, nil] autorelease];
[item1 release];
[item2 release];
However, this is only in iPhone OS 3.2, which would make it iPad only at this point. There's an example here (scroll down to "Custom Edit Menu Items").
As for altering the existing items, I do not believe that is possible currently.
All I want is to display some simple text in my viewController and have the hyperlinks autoparsed. When the user clicks on the link I want the control to somehow do a callback where I can do something with the URL. How can I achieve this?
I've already looked through the TTCatalog for hours. I have also tried looking into the source code of three20 as well as looking at the stack trace. No help. I just can't figure out how my app can react to the click of the URL. Any hints please?
Hard to help without seeing what you've already tried, but you should be able to do something like the following:
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc]
initWithFrame:someFrame] autorelease];
NSString* labelText = #"This should work";
label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];
[someView addSubview:label];
You can then use TTNavigator and TTURLMap to map custom-uri://some/url to a particular controller in your application, or handle it yourself in your application delegate. The best place to find out how to do that is by looking at the TTNavigatorDemo sample application included in the Three20 source. Specifically, look at AppDelegate.m which is where all the URL mapping gets performed.
In addition to what Nathan says about URL mapping and links, you can also use CSS styles!
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc] initWithFrame:someFrame] autorelease];
NSString* labelText = #"This should work and
<span class=\"redText\">this should be red</span>";
label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];
[someView addSubview:label];
Then in your StyleSheet.m implement
- (TTStyle*) redText {
return [TTTextStyle styleWithFont:[UIFont systemFontOfSize:12] color:RGBCOLOR(255,0,0) next:nil];
}