如何更改MFMailComposeViewController中的button?
在我的应用程序中,我正在使用MFMailComposeViewController。 我已经在标题栏中放置了一个back
和Done
button。 我有标题栏是黑色的,但我有蓝色的button背景。 如何将button背景颜色更改为black
?
你首先必须改变button样式: barButton.style = UIBarButtonItemStyleBordered;
之后,可以使用以下代码更改导航栏button的颜色:
[[mailComposer navigationBar] setTintColor:[UIColor blackColor]];
我遵循这个来添加自定义button,取代标准的取消和发送button:
// 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]];
不幸的是,我无法replace发送button。
它只是渲染button没用。
对于Swift(我正在使用Swift 1.2)
var mc: MFMailComposeViewController = MFMailComposeViewController() mc.mailComposeDelegate = self mc.setSubject(emailTitle) mc.setToRecipients(toRecipients) mc.navigationBar.tintColor = UIColor.blackColor()