How to change buttons in MFMailComposeViewController?

ぃ、小莉子 提交于 2019-12-01 15:02:37

问题


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 color, but I have the button background in blue color. How to change the button background color to black in color?


回答1:


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]];



回答2:


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.




回答3:


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()


来源:https://stackoverflow.com/questions/7205502/how-to-change-buttons-in-mfmailcomposeviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!