In my app I am using the MFMailComposeViewController. I have placed a back
and Done
button in the title bar. I have the title bar to be in black co
I followed this to add custom buttons replacing the standard cancel and send buttons:
// Fetch the UINavigationItem object of the nav bar
UINavigationItem *mailVCNavItem = [mailVC.navigationBar.items objectAtIndex:0];
// Get the old bar button item to fetch the action and target.
UIBarButtonItem *oldCancelBarButton = [mailVCNavItem leftBarButtonItem];
// Create your new custom bar button item.
// In my case I have UIButton with image set as a custom view within a bar button item.
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"backButton.png"] forState:UIControlStateNormal];
[backButton addTarget:oldCancelBarButton.target action:oldCancelBarButton.action forControlEvents:UIControlEventTouchUpInside];
backButton.bounds = CGRectMake(0.0, 0.0, 40.0, 25.0);
[[barButtonItems objectAtIndex:0] setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:backButton]];
Unfortunately I wasn't able to replace the Send button.
It just renders the button useless.
For Swift (I am using Swift 1.2)
var mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setToRecipients(toRecipients)
mc.navigationBar.tintColor = UIColor.blackColor()
You first have to change the button style:
barButton.style = UIBarButtonItemStyleBordered;
Afterwards, the color of the navigation bar buttons can be changed with the following code:
[[mailComposer navigationBar] setTintColor:[UIColor blackColor]];