UIActivityViewController - how to change the cancel button text

Does anyone know how to change the default text value of the UIActivityViewController cancel button? The default is Cancel. But I want to change it, for example. be in another language.

How to do it? Thanks!

+6
source share
4 answers

You can not. However, the Cancel button is localized by default. By the way, you can create your own controller if you want to. And you can fill it with UIActivity objects. Note that when you look at this class, when docs talk about activityController , it is any UIViewController .

+1
source

Update: The code below worked only on iOS7.

As Rickles said, you don't need to tweak the text to be localized. But just in case, someone has every reason for this, here is the code:

 NSArray *activityItems = @[@"Test"]; UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; NSAttributedString *as = [[NSAttributedString alloc] initWithString:@"Custom Text" attributes:@{NSForegroundColorAttributeName:[UIColor greenColor]}]; [[UIButton appearanceWhenContainedIn:[UIActivityViewController class], nil] setAttributedTitle:as forState:UIControlStateNormal]; [self presentViewController:activityController animated:YES completion:nil]; 

enter image description here

+3
source

As others have noted, the button is localized by the system; you cannot change it. At least on iOS 11. But I also struggled with this, and the button retained the Cancel header even after changing the system language.

This post helped me successfully localize the Cancel button in the general sheet and work on the UIDatePicker in the countdown timer mode , which also resisted previous attempts to localize the system: Why doesn't the UIActivityViewController display a localized cancel line?

Add this line to your info.plist :

enter image description here

+1
source

Cancel button will be localized. You can also try REActivityViewController

0
source

All Articles