如何更改MFMailComposeViewController中的按钮?

时间:2011-08-26 13:38:24

标签: objective-c ios mfmailcomposeviewcontroller

在我的应用程序中,我正在使用MFMailComposeViewController。我在标题栏中放置了backDone按钮。我的标题栏是黑色的,但我有蓝色的按钮背景。如何将按钮背景颜色更改为black颜色?

3 个答案:

答案 0 :(得分:17)

首先必须更改按钮样式:     barButton.style = UIBarButtonItemStyleBordered;

然后,可以使用以下代码更改导航栏按钮的颜色:

[[mailComposer navigationBar] setTintColor:[UIColor blackColor]];

答案 1 :(得分:4)

我按照此处添加了自定义按钮,取代了标准的取消和发送按钮:

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

很遗憾,我无法更换发送按钮。

它只是使按钮无效。

答案 2 :(得分:1)

对于Swift(我使用的是Swift 1.2)

var mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setToRecipients(toRecipients)
mc.navigationBar.tintColor = UIColor.blackColor()