更改MFMailComposeViewController的工具栏颜色

19

我的iPhone应用中使用了带有色调的导航栏和全局UIToolbar。在我的信息视图中,我有一个按钮打开MFMailComposeViewController,但是在该视图顶部的工具栏(包含“取消”和“发送”按钮)仍然是蓝色的。我是这样调用MFMailComposeViewController的:

-(void)displayMailSheet
{

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"..."];

    NSArray *toRecipients = [NSArray arrayWithObject:@"..."]; 

    [picker setToRecipients:toRecipients];

    [self presentModalViewController:picker animated:YES];
    [picker release];

}

我能否更改视图工具栏的颜色?如果可以,我该如何做到这一点?


2
你尝试过设置 picker.navigationBar.tintColor 吗? - Ole Begemann
6个回答

39

给你:

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

iOS 8.0版本

 [[picker navigationBar] setBarTintColor:[UIColor blackColor]];

谢谢您的提示。这个建议已经在上面作为评论发布了,但现在我可以将问题标记为已解决;-) - iYassin
2
对于iOS 7.0应用程序,这是不起作用的。请查看来自eggboxderek的提示。 - Nick N
setTintColor现在会更改栏按钮,所以通常您会在视图控制器上使用setBarTintColor,但这对于MFMailComposeViewController无效。 - Leon

12
关于 iOS7 中此功能的一个小细节 - tint color 属性不再影响整个栏的颜色,而仅仅改变“发送”和“取消”按钮的颜色(在 iOS7 样式中被简单地着色为标签)。如果你已经将标题栏颜色改为白色或透明等颜色,那么这一点值得注意,因为在 iOS7 下,“发送”和“取消”按钮将不再可见。

5

你可以从AppDelegate全局执行它

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationbar-background.png"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault]; // MFMailComposeViewController's navigationBar backgroundcolor 

NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];//MFMailComposeViewController's navigationBar text color 

3

我想强调一下,关于苹果拒绝你的应用程序的帖子是旧帖子。以下是当前MFMailComposeViewController文档的摘录...

重要提示:该类的视图层次结构是私有的,您不得修改它。但是,您可以使用UIAppearance协议自定义实例的外观。


2

试试这个:

MFMailComposeViewController *mailController  = [MFMailComposeViewController new];

[mailController.navigationBar setTintColor:[UIColor colorWithHue:240.0f/359.0f
                                                      saturation:85.0f/100.0f 
                                                      brightness:60.0f/100.0f 
                                                           alpha:0.0f]];

-3

来自官方MFMailComposeViewController类参考:

重要提示:邮件撰写界面本身不可定制,也不应由您的应用程序进行修改。[...]

我认为最好选择默认的邮件撰写界面而不做任何更改。否则,苹果可能会拒绝您的应用程序。

让我们在这里问一下是否有人有这样的经验。


你可以从AppDelegate全局进行操作。 - Erhan Demirci

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接