Override iPhone copy menu captions on a long-press? - iphone

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.

Related

How to make iPhone Share Sheet black?

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

How can I have 2 leftBarButtonItems in iPhone app, and 1 be the default back button?

I would like 2 leftBarButtonItems, but leave one of the items as the default back button for Navigation Controllers. I have set up:
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:archives, ???, nil];
where archives is a UIBarButtonItem I created, but do not know what the default back button is to include in the array. Any suggestions?
Make sure you set leftItemsSupplementBackButton to YES.
self.navigationItem.leftItemsSupplementBackButton = YES;
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:archives, nil];

The Custom UIMenuItem is too wide in IOS5

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.

How to get selection text from UIWebView?

, 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;

Reload / Refresh tab bar items in a ViewController ?

I am trying to change images of my tabbar in a ViewController, but to display the new images, I must click on each tab bar item.
for (CustomTabBarItem *myItem in self.tabBarController.tabBar.items){
myItem.enabled = YES;
myItem.badgeValue = #"1";
UIImage *myImage = [[UIImage alloc] initWithContentsOfFile:[[DesignManager sharedManager] getPathOfFile:#"test.png"]];
*myItem.imageSelect= *myImage; // change images of each item. don't appear if I dont click on the item
}
Anyone know How can I can display directly these images?
Thanks
You need to replace the old tab bar item with a new one. You can't update the image dynamically otherwise.
The easiest way to do this is to set the tabBarItem property of the view-controller represented by a given tab. If you wanted to do this from within that view controller, just write:
self.tabBarItem = [[UITabBarItem alloc] initWithTitle: #"title" image: myImage: tag: nil];
Or, you could do this from somewhere else, say your app delegate:
UIViewController* vc = [tabBarController.viewControllers objectAtIndex: 3];
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle: #"title" image: myImage: tag: nil];
I know this is an old question. I ran into the same problem when I need to update the badge value from another active tab. Creating another UITabBarItem will solve your current problem but causes potential memory leak when this code is called many times. Plus, when other view controllers access the tab, they do not have reference to newly created UITabBarItem. My trick is
vc.tabBarItem = vc.tabBarItem;
It works for me.