5

I want to customize MFMessageComposeViewController with a specific image for the navigation bar and a simple white color for status bar, navigation bar's title and cancel button. The only thing I can't do is to change the cancel button's color. Here is my implementation:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBar.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];

MFMessageComposeViewController *sms = [[MFMessageComposeViewController alloc] init];

if([MFMessageComposeViewController canSendText]){

   sms.body = string;
   sms.recipients = number;
   sms.messageComposeDelegate = self;
   [self presentViewController:sms animated:YES completion:^{

        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }];
}

I also try with [sms.navigationBar setTintColor:[UIColor whiteColor]]; but It doesn't work.

EDIT I finally find a solution: just add this line of code under the last [UINavigationBar appearance]:

[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil].tintColor = [UIColor whiteColor];

1 Answers1

0

I tried the edit with the solution and it didn't quite work. However, I found a solution with some help:

MFMessageComposeViewController *messageController = [MFMessageComposeViewController new];
[messageController.navigationBar setBarTintColor: [UIColor redColor]];
[self presentViewController:messageController animated:true completion:nil];
[UIView appearanceWhenContainedInInstancesOfClasses:[NSArray arrayWithObject:[MFMessageComposeViewController class]]].tintColor = [UIColor redColor];

MFMessageComposeViewController: Cannot Style "Cancel" Button in Dark Mode

Eli017
  • 31
  • 7