Does anybody know how to change the standard cancel button text value of UIActivityViewController? By default it's "Cancel". But I want to change it e.g. to be in different language.
How to do it? Thanks!
Update: The code below only worked on iOS7.
Like Rikkles said, you don't need to customise the text to make it localized. But just in case someone ever has a good reason to do this, here's 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];
You can't. However, the Cancel button is localized by default.
Incidentally, you can create your own controller if that's what you want. And you can fill it with UIActivity
objects. Note that when you look at that class, when the docs talk about an activityController
, it's any UIViewController
.
As others point out, the button is localized by the system, you can't change it. At least on iOS 11. But I was struggling with that as well and the button kept its Cancel
title even after changing the system language.
This post helped me to successfully localize the Cancel button of the share sheet and worked on a UIDatePicker
in countdown timer mode that resisted previous system localization attempts as well: Why UIActivityViewController doesn't display localized cancel string?
Add this row into your info.plist
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With