2011-08-26 36 views

回答

17

你首先要改变的按钮样式: barButton.style = UIBarButtonItemStyleBordered;

之后,导航栏按钮的颜色可以用下面的代码进行更改:

[[mailComposer navigationBar] setTintColor:[UIColor blackColor]]; 
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]]; 

不幸的是我wa无法替换发送按钮。

它只是呈现按钮没用。

+0

不中iOS7为我工作,但看上去很聪明的代码。 – quantumpotato

1

对于斯威夫特(我用的雨燕1.2)

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

完美的作品!谢谢! – Lachtan