Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set text color of Send and Cancel buttons in the mail composer when presented from the UIActivityViewController in iOS7

I am using the UIActivityViewController to share items in iOS7. When I tap on the Mail option, it pops up the mail composer, but the Cancel and Send buttons on the navigation bar and the navigation bar itself are blue, making it very difficult to read, so I want to change their color. It's working in iOS6 but not in iOS7.

I tried

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], UITextAttributeTextColor, [UIColor clearColor], UITextAttributeTextShadowColor, nil] forState:UIControlStateNormal]; 

which works in iOS6, and I tried

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]]; [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]]; 

which causes the color to flash red the first time the app is run before immediately switching back to the blue color.

like image 488
Jonathan Shih Avatar asked Oct 14 '13 19:10

Jonathan Shih


1 Answers

Managed to change the text color of the Send and Cancel buttons, which are on the UINavigationBar in the MFMailComposerViewController (both Send and Cancel) and MFMessageComposeViewController (only Cancel), when presented from UIActivityViewController.

Using an UIActivityViewController, tap on Messageor Mail:

Using an UIActivityViewController

You'll notice that the default text color of the Send and Cancel buttons is blue:

Default blue colors

In order to change that, in the AppDelegate.m class, in the didFinishLaunchingWithOptions method, insert the following line:

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]]; 

This results in:

Changed to white

You can also use other colors, for example:

[UIColor purpleColor];

Change to purple

[UIColor greenColor];

Changed to green

How did I test this? I noticed this solution works for the following:

  • with Xcode 5.1, in the iOS 7.1 simulator, building as base iOS SDK 7.1 (can be chosen from selecting the project file -> Build Settings -> Base SDK. Also, selected from General -> Deployment Target -> 7.1)
  • with Xcode 5.1, on an iPhone 4, building as base iOS SDK 7.0 (can be chosen from selecting the project file -> Build Settings -> Base SDK. Also, selected from General -> Deployment Target -> 7.0)
  • with Xcode 5.1, on an iPhone 4, building as base iOS SDK 7.1 (can be chosen from selecting the project file -> Build Settings -> Base SDK. Also, selected from General -> Deployment Target -> 7.1)

It didn't work when testing with:

  • with Xcode 5.1, in the iOS 7.0 simulator, building as base iOS SDK 7.0 (can be chosen from selecting the project file -> Build Settings -> Base SDK. Also, selected from General -> Deployment Target -> 7.0)

Therefore it should be safe to use, as I believe the behavior on the actual device matters more than the behavior in the iOS simulator. If anyone knows why it doesn't work in the iOS 7.0 simulator, I would like to know. :)

like image 198
Alex Avatar answered Sep 23 '22 02:09

Alex